general questions about DNS routing

Question: Question. I have a Windows AD Domain and there is one part that is a mystery to me: how is the Windows Domain / DNS Server doing lookups for domains outside of the Windows domain?
In a simple home network, DNS request routing is easy to understand:
Generic Example: Client machine -> (defined DNS or from DHCP) ->
                ->Router / Gateway -> (usually ISP DNS) -> DNS root servers -> Internet
Specific Example: 192.168.1.101 -> 192.168.1.1 -> 18.104.22.168 -> DNS root servers -> Internet

In contrast, the path I currently see for my AD network is this:
Client Machine -> Windows Domain / DNS -> ??????? -> DNS root servers -> Internet

If I check the network settings on my Domain Server, the DNS is set to the alternate DNS server (secondary Domain Server), itself, and the loopback, and nothing else.
My internet works, so somehow the Windows Domain server is smart enough to get DNS info from a server upstream, but where and how is this defined?
Answer: Several ways your DCs could query an external name server:

Root hints
Global forwarders
Explicitly defined stub zones, delegations or conditional forward zones
Settings on your DC's network interface - which you've checked.

I'm going to guess #1 or #2. Your question only includes checking network settings - have you checked the DNS manager on the DCs?
If all the above are blank, there's something unintended going on and you should perhaps track outgoing DNS queries using wireshark.
Comment: Windows DNS is configured to use the root hint servers by default. Absent any forwarders it will use the root hint servers.
Answer: DNS consists of two quite different parts. One part is responsible for publishing the data, and the other part is responsible for accepting DNS requests from clients and trying to answer those requests by gathering data. DNS servers performing the role of publishing data are often called "authoritative" servers, even though that isn't really a technically correct name. Personally, I prefer the name "DNS content server", but that term is not in very wide use. Servers that accept and answer requests from clients are often called "resolving" servers.
This is actually quite similar to how HTTP servers and HTTP proxies work: HTTP servers publish the data, and HTTP proxies accept requests from clients (browsers) and will contact servers to gather the data the client asked for. A difference between Web browsers and DNS clients is that a DNS client is not capable of contacting content DNS servers by itself. A DNS client has to use a DNS resolving server, while a Web browser is perfectly able to function without a HTTP proxy.
Because DNS information is stored in a hierarchical and distributed way, to answer a single query you'll need information from several DNS content servers, likely located all over the world. When a DNS client wants to know the address of "www.serverfault.com", it can just send that request to a DNS resolving server. That DNS resolving server then has to perform the actual work of contacting DNS servers all over the world.
First, the resolving DNS server sends the entire query to a root server (which is a content DNS server). That root server doesn't have a complete answer, but it does know which DNS content servers have more information about names in the ".com" domain. So the DNS resolver now sends the entire query to one of the ".com" content DNS servers. That server also does not have a complete answer, but it does know which DNS content servers have more information about names in the servervault.com domain. The resolving DNS server will keep asking content DNS servers around the world until it has a complete answer for the client. Of course, the resolving DNS server will cache information along the way: it will not contact the root content DNS servers for each query in a ".com" domain if it knows from its cache where the ".com" content DNS servers are.
A "forwarder" is simply a resolving DNS server that sends client queries to another (preconfigured) resolving DNS server, instead of trying to answer them itself by contacting content DNS servers all over the world. Home routers often contain a resolving DNS server, which is configured to use the resolving DNS server of the ISP as a forwarder.
It can get confusing when the two different roles (both content serving and resolving) come together in one DNS server. This is more or less what happens with Active Directory. In Active Directory, DNS is used to publish information about where certain services can be found. For example, when a client in the domain ad.example.com wants to contact a Kerberos Password Change Server for its domain, it issues a DNS request for a SRV record called _kpasswd._tcp.ad.example.com. This DNS request is sent, just like any other DNS request, to the resolving DNS server configured in the client. The resolving DNS server then goes to work trying to answer the request.
This is where it can get a bit confusing. The DNS resolving server might know that it is part of a specific Active Directory domain, which means it can recognize incoming queries for names in that domain. If the resolver receives such a query, it won't contact outside DNS servers, but it can reply directly with information from the Active Directory database. If an incoming query is not for a name in the domain, the resolver either tries to answer the question itself by contacting content DNS servers, or (in case it is configured to use a forwarder) just sends the query on to another DNS resolving server. This is most likely what happens in your scenario.
What can further confuse matters are dynamic updates. In any non-trivial domain, services are not static. Domain controllers might be added or removed, etc. The same applies to workstations. This means that the information in DNS needs to be updated to reflect this. Dynamic Updates is a protocol that enables a client to modify the information that is published in DNS. A client sends a query to its resolving DNS server to find out to which content DNS server it can send the new information. In case of an Active Directory integrated DNS infrastructure, the resolving DNS server might very well have access to the database itself: in that case the resolving DNS server tells the client that it can update the information itself.
Comment: I appreciate the detailed explanation, but I already knew most of this.  What I was wondering is how the Windows DNS Server knows about DNS information outside of its Domain, when there is no place to define a specific upstream DNS server.  It appears it does so via root hints.
Comment: If you're certain that the resolver does not use a forwarder, or in other words: when the resolver does all the hard work of resolving queries by itself, then it needs to know how to find the root servers. This is indeed done by preconfigured root hints. (This differs a bit among DNS server implementations: some use root hints, while others just use a list of root servers.)

general questions about DNS routing


Problema em disposição de de produtos em Grid

Question: Tenho o site MK Gráfica onde na parte de categoria de produtos, especificamente em Banners e também em Promoções a disposição dos produtos em Grid está com problema, um ou outro produto aparece sozinho em certa linha, sendo que deveria continuar o padrão de 3 produtos. Isto pode ser visto neste link.
E o problema especificamente nesta imagem.
Tentei utilizar o css:
.row, [class*='col-'] {
    display: inline;
}

Mas não funcionou, e o estranho é que o problema aparece somente em algumas categorias.
Testei no Chrome versão 51.0.2704.103 e no Firefox.
Answer: Então Wendell o problema é que você só tem colunas(col).
Seu código hoje esta assim:
...

...

Para resolver seu problema, deveria estar assim:
...

...

Uma solução alternativa é via css.
Adicione uma altura mínima assim:
.product-layout{min-height: 370px;}

Espero ter ajudado.
Answer: Se você estiver a utilizar o Bootstrap, não esqueça de utilizar assim para que seja responsivo:

Esta div é uma coluna com col-lg-4 o tamanho dela é de 4 colunas do bootstrap para dispositivos grandes, em md (notebooks) a mesma coisa, para dispositivos sm (tablets) e xs (celulares) esta coluna ocupará o espaco de 6 colunas, por padrão o bootstrap faz uso de 12 colunas. você pode adicionar quantas divs dessas você desejar dentro de uma div row (linha), quando o tamanho estourar a soma de 12 colunas elas automaticamente passarão para baixo criando outra camada. Porem se você diferenciar as camadas com as rows, o conteúdo pode não se organizar automaticamente.
Comment: http://getbootstrap.com/css/#grid
Comment:  Bootstrap usa *larguras mínimas* para seu grid, então não precisa declarar colunas da mesma largura. Você somente precisa declarar a menor até determinada resolução e assim sucessivamente.


How to run a drupal application in github?

Question: I am trying to setup Drupal Application in Github and was able to  successfully setup the instance and moved the project to github.
Can anyone help me with as how to execute a drupal application in github,as I am finding tools to run html files but executing a drupal files seems to be a tedious task.
Answer: You can not execute Drupal in Github, just because Drupal requires a server running PHP, which isn't supported by github.

Github Pages is not a full-featured web host. It will not execute PHP, or any other arbitrary code.
Source

You could convert your Drupal site into a static site and upload it on github, but the website would not be dynamic anymore. If you decide to do this, you could host it using Github pages, but you would not be executing Drupal; instead, you would be going to show a static version of your Drupal website.
If you wish to add a static version of your website for Drupal 7, you can look at the Static Generator module. If you are running Drupal 8, you can use wget --mirror http://example.com and this will provide copy of your site's HTML.


Como abrir uma Activity a partir de uma java class?

Question: Possuo uma java class denominada Firebase, essa classe só faz
funções do firebase...
Eu estou autenticando um novo usuário no firebase, até ai tudo bem.. O
problema é que eu não consigo passar para uma outra Activity, está
dando o seguinte erro:

05-24 23:56:38.335 15742-15742/com.hotelaria.neoris.checkincheckout E/AndroidRuntime: FATAL EXCEPTION: main
    Process: com.hotelaria.neoris.checkincheckout, PID: 15742
    java.lang.NullPointerException: Attempt to invoke virtual method 'android.app.ActivityThread$ApplicationThread android.app.ActivityThread.getApplicationThread()' on a null object reference
        at android.app.Activity.startActivityForResult(Activity.java:4488)
        at android.support.v4.app.BaseFragmentActivityApi16.startActivityForResult(BaseFragmentActivityApi16.java:54)
        at android.support.v4.app.FragmentActivity.startActivityForResult(FragmentActivity.java:68)
        at android.app.Activity.startActivityForResult(Activity.java:4445)
        at android.support.v4.app.FragmentActivity.startActivityForResult(FragmentActivity.java:751)
        at android.app.Activity.startActivity(Activity.java:4806)
        at android.app.Activity.startActivity(Activity.java:4774)
        at com.hotelaria.neoris.checkincheckout.models.objects.Firebase$1.onComplete(Firebase.java:35)
        at com.google.android.gms.tasks.zzf.run(Unknown Source:23)
        at android.os.Handler.handleCallback(Handler.java:790)
        at android.os.Handler.dispatchMessage(Handler.java:99)
        at android.os.Looper.loop(Looper.java:164)
        at android.app.ActivityThread.main(ActivityThread.java:6494)
        at java.lang.reflect.Method.invoke(Native Method)
        at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:438)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:807)

Firebase.class:
package com.hotelaria.neoris.checkincheckout.models.objects;

import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.support.annotation.NonNull;
import android.support.v7.app.AppCompatActivity;
import android.util.Log;
import android.widget.Toast;

import com.google.android.gms.tasks.OnCompleteListener;
import com.google.android.gms.tasks.Task;
import com.google.firebase.auth.AuthResult;
import com.google.firebase.auth.FirebaseAuth;
import com.google.firebase.database.DatabaseReference;
import com.google.firebase.database.FirebaseDatabase;
import com.hotelaria.neoris.checkincheckout.activitys.SigninActivity;;

public class Firebase extends AppCompatActivity {

    private final FirebaseDatabase mFirebaseDatabase = FirebaseDatabase.getInstance();
    private final FirebaseAuth mFirebaseAuth = FirebaseAuth.getInstance();
    private final DatabaseReference mDatabaseReference = mFirebaseDatabase.getReference();

    public void writeNewUser(final Activity activity, final Context activityContext, String email, String password){
        this.mFirebaseAuth.createUserWithEmailAndPassword(email, password)
                .addOnCompleteListener(activity, new OnCompleteListener<AuthResult>() {
                    @Override
                    public void onComplete(@NonNull Task<AuthResult> task) {
                        if(task.isSuccessful()) {
                            Toast toast = Toast.makeText(activityContext,"SUCESSO, CONTA CADASTRADA!", Toast.LENGTH_SHORT);
                            toast.show();

                            Intent intent = new Intent(activity.getApplicationContext(), SigninActivity.class);
                            startActivity(intent);
                            finish();
                        } else {
                            Toast toast = Toast.makeText(activityContext,"OPS ACONTECEU ALGUM ERRO...", Toast.LENGTH_SHORT);
                            toast.show();
                        }
                    }
                });
    }

}

SignUpActivity.class:
package com.hotelaria.neoris.checkincheckout.activitys;

import android.content.Context;
import android.content.Intent;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ImageButton;
import android.widget.Toast;

import com.hotelaria.neoris.checkincheckout.R;
import com.hotelaria.neoris.checkincheckout.models.objects.Firebase;

public class SignupActivity extends AppCompatActivity {

    private Firebase mFirebase;

    private EditText mEditText;
    private ImageButton mImageButton;
    private Button mButton;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_signup);

        this.onClickButtonBackToLoginActivity();
        this.onClickButtonRegisterUser();
    }

    private void onClickButtonBackToLoginActivity(){
        this.mImageButton = findViewById(R.id.imageButtonBackToLoginActivity);
        this.mImageButton.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent = new Intent(SignupActivity.this, LoginActivity.class);
                startActivity(intent);
                finish();
            }
        });
    }

    private void onClickButtonRegisterUser(){
        this.mButton = findViewById(R.id.buttonRegisterUser);
        this.mButton.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Context activityContext = getApplicationContext();

                if(checkEditText() == true) {
                    Toast toast = Toast.makeText(activityContext, "PREENCHA O E-MAIL E A SENHA !!", Toast.LENGTH_SHORT);
                    toast.show();
                } else {
                    mFirebase = new Firebase();
                    mFirebase.writeNewUser(SignupActivity.this, activityContext, getEmail(), getPassword());
                }
            }
        });
    }

    private Boolean checkEditText(){
        if(getEmail().isEmpty() || getPassword().isEmpty()){
            return true;
        } else {
            return false;
        }
    }

    private String getEmail(){
        this.mEditText = findViewById(R.id.editTextEmail);
        return this.mEditText.getText().toString();
    }

    private String getPassword(){
        this.mEditText = findViewById(R.id.editTextPassword);
        return this.mEditText.getText().toString();
    }

}

SignInActivity.class
package com.hotelaria.neoris.checkincheckout.activitys;

import android.content.Intent;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.ImageButton;

import com.hotelaria.neoris.checkincheckout.R;

public class SigninActivity extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_signin);

        this.onClickButtonBackToLoginActivity();
        this.onClickButtonGoToMainActivity();
    }

    public void onClickButtonBackToLoginActivity(){
        ImageButton imageBtnSignInActivity = findViewById(R.id.imageButtonBackToLoginActivity);
        imageBtnSignInActivity.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent = new Intent(SigninActivity.this, LoginActivity.class);
                startActivity(intent);
                finish();
            }
        });
    }

    public void onClickButtonGoToMainActivity(){
        Button imageBtnSignInActivity = findViewById(R.id.buttonRegisterUsr);
        imageBtnSignInActivity.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent = new Intent(SigninActivity.this, MainActivity.class);
                startActivity(intent);
                finish();
            }
        });
    }
}

Comment: Porque você não faz a autenticação em uma activity em branco que a partir dela td é autenticado, caso exista usuário, ele vá para parte principal, caso não, ele vá pra tela de login? Eu geralmente faço isso, crio uma activity em branco com nome start, a primeira ser iniciado é ela, caso exista usuário vai pra tela principal, caso não, vai pra tela de login
Comment: @WotonSampaio poderia me dar um exemplo em código por gentileza?
Comment: Ah, agr vi direito seu código, ao invés de `activity.getApplicationContext()` usa o próprio contexto que você passou, o `activityContext` nesse linha: `Intent intent = new Intent(activity.getApplicationContext()...`
Answer: Aconselho você utilizar estes métodos dentro da sua activity mesmo.
Experimente alterar este método da classe Firebase.class
public void writeNewUser(final Activity activity, final Context activityContext, String email, String password){
        this.mFirebaseAuth.createUserWithEmailAndPassword(email, password)
                .addOnCompleteListener(activity, new OnCompleteListener<AuthResult>() {
                    @Override
                    public void onComplete(@NonNull Task<AuthResult> task) {
                        if(task.isSuccessful()) {
                            Toast.makeText(activityContext,"SUCESSO, CONTA CADASTRADA!", Toast.LENGTH_SHORT).show();

                            Intent intent = new Intent(activityContext, SigninActivity.class);
                            startActivity(intent);
                            finish();
                        } else {
                            Toast.makeText(activityContext,"OPS ACONTECEU ALGUM ERRO...", Toast.LENGTH_SHORT).show();
                        }
                    }
                });
}

Dentro das Activity você está inserindo os métodos onClick mas não está referenciando a um botão. Isso pode ser feito somente se dentro do xml desta activity possui o método android:onClick="nomeMetodo" e este método tem como parâmetro uma View como neste código.
Dentro da SignInActivity.class coloque o seguinte código:
package com.hotelaria.neoris.checkincheckout.activitys;

import android.content.Intent;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.ImageButton;

import com.hotelaria.neoris.checkincheckout.R;

public class SigninActivity extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_signin);

        Button btn1 = (Button) findViewById(R.id.buttonId1);
        Button btn2 = (Button) findViewById(R.id.buttonId2);

        btn1.setOnClickListener(new View.OnClickListener() {
             public void onClick(View v) {
                Intent intent = new Intent(SigninActivity.this, LoginActivity.class);
                startActivity(intent);
                finish();
             }
         });

         btn2.setOnClickListener(new View.OnClickListener() {
             public void onClick(View v) {
                Intent intent = new Intent(SigninActivity.this, MainActivity.class);
                startActivity(intent);
                finish();
             }
         });
    }

}

Se quiser colocar alguma imagem no seu botão coloque a imagem na pasta drawable e no atributo android:background coloque o caminho desta imagem. Segue:
<Button
    android:id="@+id/Button01"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:background="@drawable/imagem" />

E mantenha este modelo de código para a outra activity SignUpActivity.class.


Duplicated node when getting mysql hierarchy into JSON object using Java

Question: I am using Spring to return a JSON object as a response from a hierarchy represented in two Mysql tables.
------------    -----------------
| Concepts |    | Relationships |
|----------|    |---------------|
| id       |    | relation_id   |
| title    |    | concept_id_1  |
------------    | concept_id_2  |
                -----------------

In order to do this I have the method getChildren that returns all children of a concept.
I am using these methods as follows to get a hierarchical structure from mysql.

public String getPath(Concept concept, Set<Concept> children){
    if (children.size() > 0){

        Set<Concept> newNodes = new HashSet<>();
        ArrayList<String> returnedStrings = new ArrayList<>();
        String currentString = getChildrenString(concept, children);
        return currentString;
    }
    return getMainString(concept, "");
}

public String getChildrenString(Concept concept, Set<Concept> children){
    ArrayList<String> returnedStrings = new ArrayList<>();
    for (Concept node : children){
        String currentString = "{'id':" + concept.getId() + ","
                                + "'title':'" + concept.getDescription() + "',"
                                + "'nodes':[" + getPath(node, getChildrens(node)) + "]}";
        returnedStrings.add(currentString);
    }
    StringBuilder fullList = new StringBuilder();
    for (String s: returnedStrings){
        fullList.append(s+"");
    }
    return fullList.toString();
}

public String getEmptyString(Concept concept){

    return "{'id':"+ concept.getId() + ","
            + "'title':'" + concept.getDescription() + "',"
            + "'nodes': []}";
}

It all starts from here from a known concept.
String test = getPath(concept, children);

The CORRECT response I am expecting for certain concept is like this:
{
    'id': 160000,
    'title': 'root',
    'nodes': [{
        'id': 160039,
        'title': 'Therapeutic Uses',
        'nodes': [{
            'id': 160001,
            'title': 'Anti-Allergic Agents',
            'nodes': []
        }, {
            'id': 160002,
            'title': 'Anti-Infective Agents',
            'nodes': [{
                'id': 160004,
                'title': 'Anti-Infective Agents, Local',
                'nodes': [{
                    'id': 160015,
                    'title': 'Hands Sanitizers',
                    'nodes': []
                }]
            }]
        }]
    }]
}

However, this code is returning the following string where the nodes are being duplicated, and I can't understand why this is happening or which part of the recursivity is causing this problem.
You can see the concept 160039 is repeating in the answer returned by this code.
{
    'id': 160000,
    'title': 'root',
    'nodes': [{
        'id': 160039,
        'title': 'Therapeutic Uses',
        'nodes': [{
            'id': 160001,
            'title': 'Anti-Allergic Agents',
            'nodes': []
        }]
    }, {
        'id': 160039,
        'title': 'Therapeutic Uses',
        'nodes': [{
            'id': 160002,
            'title': 'Anti-Infective Agents',
            'nodes': [{
                'id': 160004,
                'title': 'Anti-Infective Agents, Local',
                'nodes': [{
                    'id': 160015,
                    'title': 'Hands Sanitizers',
                    'nodes': []
                }]
            }]
        }]
    }]
}

What could be the cause of this in my code, how can I get the correct response?
Answer: After writting this question I noticed I was returning the full string for each father node, that's why they were repeating.
Changing this method to return the string after it gets all the other children strings for a node, gives me the correct answer.
public String getChildrenString(Concept concept, Set<Concept> children ){
    ArrayList<String> returnedStrings = new ArrayList<>();

    for (Concept node : children){
        String nodeString = getPath(node, hierarchy.getChildrens(node), entity, hierarchy);
        returnedStrings.add(nodeString);
    }

    StringBuilder fullList = new StringBuilder();
    for (String s: returnedStrings){
        fullList.append(s+"");
    }
    return "{'id':" + concept.getId() + ","
            + "'title':'" + concept.getDescription() + "'," +
            "'nodes':[" + fullList.toString() + "]}";
}


Função javaScript não funciona quando usado ng-include angularJs

Question: Estou fazendo uma injeção de tamplate via ng-include do angularJs.
Dentro desse template tenho um botão  que chama um modal o qual é inserido no template por outra injeção. Até então tudo funciona corretamente. Dentro do modal eu tenho uns inputs e um botão que deveria  inserir as informações na listagem, mas é isso que não funciona. Ele chama a função certo, passa os valores mas não insere na listagem. Vejamos o código.
app.controller("notasFiscaisProdutorLiquidacaoController", function($scope,$rootScope,$timeout){

    jQuery(document).ready(function(){
        jQuery("#btnAbrirModalNota").click(function(){
            jQuery("#modalAdicionarProduto").modal();
        });

        jQuery("#btnAbrirModalNotaLiquidacao").click(function(){
            jQuery("#modalAdicionarNotaLiquidacao").modal();
        });

    });

    $scope.etapa=1;
    $scope.primeiraEtapa='./arrecadacao/producaoPrimaria/producaoPrimariaPaginas/notasFiscais/primeiraEtapa.html'
    $scope.segundaEtapa='./arrecadacao/producaoPrimaria/producaoPrimariaPaginas/notasFiscais/segundaEtapa.html'
    $scope.terceiraEtapa='./arrecadacao/producaoPrimaria/producaoPrimariaPaginas/notasFiscais/terceiraEtapa.html'

    $scope.proximaEtapa = function () {
        $scope.etapa++;
    }
    $scope.anterior = function () {
        $scope.etapa--;
    }

    $scope.notas=[];
    $scope.nota={};
    $scope.nota.flagARendimento="0";
    $scope.tipoNota="0";

    $scope.adicionarNota = function (fechar) {
        $scope.notas.push($scope.nota);
        $scope.nota={}
        if (fechar) {
            $('#modalAdicionarProduto').modal('hide');
        }
    };

});

Html principal

<meta charset="UTF-8"/>
<base href="/"></base>

                    <button style="color: black;" type="button" ng-click="anterior()" ng-disabled="etapa==1" class="btn btn-default btnFiscal" id="btnVoltar">Voltar </button>
                    <button style="color: black;" type="button" ng-click="proximaEtapa()" ng-disabled="etapa==3"class="btn btn-default btnFiscal" id="btnProximo">Próximo </button>

Template html

Primeira etapa

    <form novalidate name="frmNotasMultiplas" id="formCadastro1" role="form">

                            Data emissão <input ng-required="nota.idSituacao==1" type="date" class="form-control" ng-model="nota.dataEmissao" date-format />

                        Série
                        <input ng-required="true" maxlength="3" type="text" class="form-control"
                              ng-model="nota.serie" />

                            <button type="button" id="btnAbrirModalProduto" class="btn btn-default" >Adicionar Produto </button>

                            Tipo
                            Série
                            Número
                            Opções

                            {{not.tipo}}
                            {{not.serie}}
                            {{not.numero}}

    </form>

modal

                <button type="button" class="close" data-dismiss="modal" ng-click="limpaModalContadores()" >×</button>

Produto

                <form novalidate name="frmNota" id="formCadastro" role="form">

                            Tipo
                            <input type='text' class="form-control"  ng-model="nota.tipo" style="width: 100%"/>

                            Série
                            <input   type="text" class="form-control" ng-model="nota.serie"  />

                            Número
                            <input   type="text" class="form-control" ng-model="nota.numero"  />

                </form>

                <button style="color: black;" type="button" class="btn btn-default btnSalvar1" id="btnSalvarRegistro" ng-click="adicionarNota(true)">Adicionar</button>
                <button style="color: black;" type="button" class="btn btn-default btnSalvar1" ng-click="adicionarNota(false)" id="btnSalvarModal" >Adicionar e novo</button>
                <button style="color: black;" type="button" class="btn btn-default btnCancelar closed" ng-click="limpaModalAdicionarNotas()" data-dismiss="modal">Cancelar</button>

Answer: Você está limpando o objeto $scope.nota com $scope.nota={}.
Tente fazer push com cópia assim:
$scope.notas.push(angular.copy($scope.nota));

Observei que você apenas exibe a listagem se tipoNota==1, não vejo em nenhum momento você atribuindo tipoNota para 1, ela é sempre 0.
Comment: não funcionou persiste o problema.
Comment: Observei que você apenas exibe a listagem se tipoNota==1, não vejo em nenhum momento você atribuindo tipoNota para 1, ela é sempre 0.
Answer: Em todos os templates (principal, template e modal) o controller notasFiscaisProdutorLiquidacaoController é adicionado. Para o angular, toda vez que você adiciona um controller no ng-controller é criado uma nova instância. Talvez neste caso, seu script esteja tentando acessar uma variável que está em outro escopo (outra instância), segue um exemplo de controller adicionado duas vezes em um template:

angular.module('teste',[]);
var test = angular.module('teste');
angular.module('teste').controller('testCtrl', function($scope){
  $scope.someModel = {'value': 0}
  console.log('new instance');
})

          <input type="number" ng-model="someModel.value">

value in controller: {{someModel.value}}

          <input type="number" ng-model="someModel.value">

value in controller: {{someModel.value}}


Force client to send DHCP options to next-server

Question: We currently have clients connecting to a DHCP server when asking for an IP. We then redirect to next-server with some additional options.
The next server has a DNSMASQ running that should be able to get all sent options by the DHCP server.
With this current configuration for a specific machine (it does actually go through this condition):
if substring (option vendor-class-identifier, 0, 20) = "PXEClient:Arch:00007" { # UEFI-64-1
    # user-class has code 77
    option user-class "test";
    next-server nextserver.example;
    # We even tried forcing sending this option, as the client might not be asking for it:
    # 4d is 77 in hex
    option dhcp-parameter-request-list = concat(option dhcp-parameter-request-list,4d);
}

When checking all traffic on the next server side we do not see this option at all. The same happens with other options such as option vendor-class-identifier "PXEClient";
Is there anything I might be missing? It seems that the client just sends the starting options to DHCP server, then to next-server, without taking any of the specified options on the DHCP server configuration.
EDIT: dnsmasq configuration
bind-interfaces

dhcp-option=vendor:PXEClient,6,2b

dhcp-match=x86PC, option:client-arch, 0
dhcp-option-force=x86PC,211, 30

dhcp-match=BC_EFI, option:client-arch, 7
dhcp-match=X86-64_EFI, option:client-arch, 9
dhcp-match=AARCH64_EFI, option:client-arch, 11

# path refers to server address, this case it is local, as there is a separate tftp server serving these files from /tftpboot/
# Use the tag to differentiate loader
pxe-service=tag:x86PClgcy,x86PC, "netboot x86PClgcy", /test/loader/lgcy/pxelinux
pxe-service=tag:x86PC,x86PC, "netboot x86PC", /test/loader/bios/lpxelinux
pxe-service=tag:BC_EFI,BC_EFI, "netboot BC-EFI", /test/loader/uefi/bootx64.efi
pxe-service=tag:X86-64_EFI,X86-64_EFI, "netboot X86-64_EFI", /test/loader/uefi/bootx64.efi
pxe-service=tag:AARCH64_EFI, 11, "netboot AARCH64_EFI", /test/loader/arm64/bootx64.efi

# ONE pxe-service per tag:architecture only
# for defined pxe-skip-menu=<CSA>
# this requires patched version of dnsmasq
pxe-skip-menu=x86PC
pxe-skip-menu=BC_EFI
pxe-skip-menu=X86-64_EFI
pxe-skip-menu=11

# i.e. it delegates the main DHCP server to allocate the IP
dhcp-range=10.0.0.0,proxy,255.0.0.0
dhcp-range=126.96.36.199,proxy,255.192.0.0
(...)

Answer: You seem to be using ISC dhcpd. From its dhcpd.conf(5) man page:

next-server server-name;
The next-server statement is used to specify the host address of the server from which the initial boot file (specified in the filename statement) is to be loaded.  Server-name should be a numeric IP address or a domain name.

Note that the server name indicated by the next-server statement is not another DHCP server. Classically it might be a TFTP server.
If your client first sends a DHCP request to one DHCP server, then to another, it means the client rejected the offer of the first server for some reason. According to DHCP protocol specifications, there is no way for a DHCP client to accept only parts of a DHCP offer; it's all or nothing.
Comment: AFAIU in this case, the DNSMASQ intercepts the request before delegating the TFTP server to provide the bootloader.


Gerando gráfico a partir de um TxT HTML

Question: Como faço para pegar os dados de um arquivo txt e jogar no html para gerar um gráfico??
Estou usando aquela ferramenta HighCharts, e gostaria de saber como jogar os valores no data, para poder gerar o gráfico.
series: [{
    name: 'Sensor 1',
    data: [12 , 15 ,30, 10,]
}]

grato desde já.
Answer:
Você pode criar seu arquivo como um .csv (comma-separated values), parecido com este:

0,1,3,7,10,10,9,7,7,6
5,4,3,3,4,4,5,6,7,10
8,8,7,8,7,7,6,4,3,2

Separá-lo em linhas usando .split:

linhas = texto.split(/\r\n|\n/);

E depois por vírgulas:

prov = linhas[j].split(',');

Depois a gente cria um objeto "gráfico", cuja propriedade .series.data são as informações do seu gráfico propriamente dito:

grafico.series[j] = [];
grafico.series[j].data = prov; // atribuindo o gráfico lido acima

E finalmente criamos o nosso chart:

Highcharts.chart('container', grafico);

O resultado:

Teste o exemplo abaixo!(Crie um arquivo separado por vírgulas e linhas como o demonstrado acima para testar)

document.getElementById('arquivo').addEventListener('change', abrirArquivo, false);

var leitor = new FileReader();
var linhas;
var grafico = [];
var prov = [];
grafico.series = [];

function abrirArquivo(a) {
  var arquivo = a.target.files[0];
  if (!arquivo) {
    return;
  }
  leitor.readAsText(arquivo);

  }

  leitor.onload = function(e) {
    var conteudo = e.target.result;
    lerDados(conteudo);
  };

function lerDados(texto) {
    linhas = texto.split(/\r\n|\n/);

    for (var j = 0; j < linhas.length; j++) {
        prov = linhas[j].split(',');
        for(var i=0; i<prov.length; i++) {
            prov[i] = parseInt(prov[i], 10);
        }

        grafico.series[j] = [];
        grafico.series[j].data = prov;
        // grafico.series[j].name = "test";
    }
    Highcharts.chart('container', grafico);
}
#container {
 min-width: 400px;
 max-width: 400px;
 height: 270px;
 margin: 0 auto
}

<input type="file" id="arquivo"/>

Gerando gráfico a partir de um TxT HTML


Multiple pairwise comparison DOE

Question: I'm going to conduct experiment with 7 products. One subject can evaluate no more than 3 products. The ultimate goal is to compare all 7 products to each other (let say, on means) and rank them.
So, full factorial design leads to 35 groups of products (with 3 products in each group) that is too much. I need to reduce it to at least 10.
Can't wrap my mind how to do this. All software that able to generate orthogonal designs need at least two factors with two levels but it seems I have one factor (with 5 levels) or five factors (with 1 level)...
May be someone can advice totally different approach to reliable rank 7 products on means?
Answer: You need an incomplete-block design, where each subject (block) sees only a subset of the products. One possibility is a balanced incomplete-block (BIB) design, in which each pair of products occurs together the same number of times. There are also partially balanced (PBIB) designs, where some pairs occur together a fixed number of times, and other pairs occur a different fixed number of times. In a BIB, each product comparison has the same variance, while in a PBIB, there are two different variances for the comparisons.
There are published tables of BIBs and PBIBs, e.g. in Cochran and Cox (1957), Experimental Designs (2nd ed.). From that source, I found a BIB design for your purpose in plan 11.7, p. 472, as follows:
Block Treatments
  1    1, 2, 4
  2    2, 3, 5
  3    3, 4, 6
  4    4, 5, 7
  5    5, 6, 1
  6    6, 7, 2
  7    7, 1, 3

So you can do this with 7 subjects, or 14 for two replications of each pair, etc. You say "at least 10" and I think you meant "at most"; but I suggest trying to go for 14 if possible. With too small an experiment, you could find the whole thing a waste because no results are clear.
PS-- I don't get how you came up with "one factor with 5 levels", "5 factors with one level", or a "full factorial with 35 groups". There is only one factor, product, and it has 7 levels.
Comment: Great answer, thank you! PS--For 35 groups (or subjects, in your term), such design where every and each product will once pair with every another product, will result in 35 subjects. I called it "full factorial design", perhaps it's wrong term in this case. For "5 factors" it was misspelling, sorry.
Comment: Hmmmm, for 7 products, the number of pairs is (7 choose 2) = 7 * 6 / 2 = 21. One of the reasons the above design works out is that each block has (3 choose 2) = 3 pairs, so with 7 blocks you have 7 * 3 = 21 pairs represented -- I.e., each possible pair represented once. Oh, but I do see that (7 choose 3) is 35, so that does explain where that number comes from. The BIB design consists of only 1 / 5 of those triples.

Multiple pairwise comparison DOE


Electric guitar out of tune on 12th fret(intonation)

Question: I just bought an electric guitar (stratocaster), and I'm a beginner, so setting it up is a welcome and annoying challenge.
The issue I have is with the intonation. The high E is fine on the open string and on the 12th fret.
The problem comes on the rest of the strings:

On the B string, I get a high E on the 12th
On the G string, I get a high E on the 12th
On the D string, I get a high E on the 12th
On the A string, I get a high G on the 12th
On the low E string, I get a high D on the 12th

Even if I moved down on B, G, D, it still stays on high E.
Also it looks like when going down from 12th to open chord it looks like it moves only 1-2 tones.
I tried to lower the saddles to be closer in height to high E, but I still have the same issues.
Any ideas what it could be?
Edit: Yeah, the problem was using the wrong tuner.
Comment: it seems that your tuner is in a mode where it will only recognize the open string pitches.
Comment: Yes, are you using an electronic tuner, and if so, what make and model is it?
Comment: @YourUncleBob You are right, I was not using a chromatic tuner
Answer: Sounds like you're using a tuner. Don't bother. Intonation can be set without. Use your ears, and press the string (any) on the 12th fret. Then play the 12th fret harmonic. Adjust the saddle for string length as needed, until they both make the same pitch. Then do the same on 19th fret. I think there's too much reliance on gadgets, and we are better off believing our ears!
Or, set up the tuner properly for guitar, or, try a different tuner. But, as said before, relying on tuners isn't always the best option. I've had a student tune an octave higher than normal; the tuner told him the string was in tune!
Comment: Aren't the harmonics of plucked string slightly different from "ideal" harmonics, and therefor not a good reference for tuning and intonating? See e.g. https://newt.phys.unsw.edu.au/jw/strings.html
Comment: This requires good pitch memory and only can set the intonation at the 12th fret. I prefer to set my intonation at other frets (usually 7th, 8th, or 9th) and my tuners have much finer resolution than my ears. Also the natural harmonics that are not perfect octaves (e.g., 19th fret) are not quite at the same pitch as equal tempered tuning, and frets are laid out to be as close to ET as possible.
Comment: Assuming both the statements are true, then using a tuner will be of no help anyway!


AD for multi-site, with zone-transfer and local DNS entries

Question: We have multiple sites in NV, TX, PA and NY. NV site is the primary site with AD and DNS server for all the users/hosts in NV. NV is also connected to TX, PA and NY through VPN. Currently, TX, PA and NY site use NV AD and DNS to reach hosts in NV. Now we want to create local AD and DNS in all three sites (PA, TX and NY). However, we still want all sites to reach NV site with DNS names. I think that part can be tackled with Zone Transfer from NV to PA, TX and NY. The most important part is to create local entries for hosts in three remote sites. Main site doesn't need to know anything about remote site's local entries. How can I achieve this? Could this be done using a child domain on main site or child domain on local site? Currently, we are in planning phase but I can do some testing and have the same domain as main site (abcxyz.com) on PA site (abcxyz.com). I created a new secondary DNS zone in PA and enabled zone transfer between PA and NV. And that works fine. However, I cannot figure out how to add local entries for PA site. --->>> Old Text
Sorry for the confusion if someone cannot understand what I am trying to achieve.
Site A has domain abcxyz.com. Site A has 2 AD servers with DNS enabled for hosts entries. Those 2 DNS server have AD integrated Primary Zone for abcxyz.io. The subnet for this site is 10.0.0.0/16 (if that matters).
We have another site, Site B. Site B currently has one AD server with the same domain as Site A (abcxyc.com). Site A and Site B are connected via IPSec tunnel. DNS service has been enabled on Site B's AD server with AD integrated Secondary Zone. Site B is in the 10.1.0.0/16 subnet.
Right now all DHCP clients point to Site B's DNS server can resolve Site A's hosts in 10.0.0.0/16 subnet because I have enabled Zone-Transfer between Site A's 2 AD DNS server and Site B's AD DNS Server.
Now the problem is I cannot create any DNS entries for Site B's Forward Lookup Zone > abcxyz.com as this is a Secondary Zone. I can create Site B's DNS entries (example ubntu1.abcxyz.com -> 10.1.100.100) in Site A AD DNS Server and can Request Update From Master Server or wait for Refresh Interval. After the update, I am seeing DNS entry for ubntu1.abcxyz.com in Site B DNS and can resolve it successfully.
This is not the desired solution because Site A in future will connect to multiple different sites, and if zone-transfer is enabled between Site A and remote sites, all DNS entries will be propagated everywhere. So ubuntu1.abcxyz.com will be propagated throughout the organization across multiple sites.
What we want is for Site B to create its own DNS entries which will remain local to its site. No other site needs to know or learn about these entries. But every site must know Site A's DNS entries. For that to happen, how do I implement the domain? Should I include all the sites under one domain, and then create child domains or sub-domains? Is there any other solution for this? I apologize as I am not an AD expert so I may be misusing some terms.
Comment: Do you use AD integrated DNS? If so, why not install DNS server roles at all sites?
Comment: I did use Primary and Secondary roles. Primary at main site and Secondary at branch site. However, since Secondary Role is just a read of primary server, I cannot create any local entries. For my branch site entries, I will have to create it on main site and request update from master at branch site. Is there an easier way of doing this? Or should I create stub zones with different domains at each branch site?
Answer: Create Active Directory integrated DNS zones instead, enabling multi-master updates and secure dynamic updates.
Structure AD DS to fit your organization. Decide if multiple domains makes sense for the organization.
Deploy DC + DNS servers at each physical location, grouped into sites. This is separate consideration from multiple AD domains, as one domain can be replicated across far-flung physical locations.
For DNS, chose between ForestDNSZones or DomainDNSzones: ForestDNSZone vs DomainDNSZones. For example, if it is acceptable that all sites see all DNS zones, replicating them everywhere is easy.
Answer: I have no idea what you're trying to accomplish based on what you've written. What you probably should do is deploy at least one Domain Controller in each site, create your sites and subnets in Active Directory Sites and Services, and convert your DNS zones to Active Directory integrated zones.


How does a golfer's follow through affect a golf ball's flight?

Question: Tiger Woods has promoted swinging with a high follow-through and a "fuller finish" to hit a high shot. Here's a video example of Woods hitting a full shot from the fairway.

Also, he abbreviates his follow-through and finish to hit a low shot, in which he refers to as his "stinger." Here's a video example of Woods hitting a low shot under the trees.

How does a golfer's follow through affect a golf ball's flight? Does follow through also dictate/promote drawing/fading the golf ball, and if so, how?
Comment: Unfortunately I cannot understand *"high follow-through"* from pictures. **How do the swing paths look like?** [Video 45:46](https://www.youtube.com/watch?v=xGMnuqKexG8&t=45m46s) shows different swing paths: is the swing path a round circle or something different with high *"follow-through"*? High follow-through could mean different angle of attack btw earth and club or some odd modification to swing path. Which one does it mean? Is this question equivalent to the question **"How does the swing path affect the path of golf ball?"**
Comment: What does `"high follow-through"` mean? Does it mean that the swing path is such that the club is rising in the contact point (i.e. positive angle of attack between the earth and club) or does it mean something else?
Comment: By drawing/fading, you mean slicing/hooking? Excellent follow-through means more control, related [question](http://sports.stackexchange.com/a/4866/630).
Comment: @hhh Drawing and hooking (and fading and slicing) are associated but not quite the same. A hook is a pronounced turning of the golf ball from right to left in flight (for the right-handed golfer) whereas a draw is a slight turning from right to left. A slice is a pronounced turning of the golf ball from left to right in flight (for the right-handed golfer) whereas a fade is a slight turning from left to right.
Comment: @hhh See edit and link to provide an explanation of a "high follow-through" or "high finish." The club is not rising in the contact point...this is in regards to after the ball is struck, how Tiger finishes. This influences ball flight.
Comment: I don't have video ready to go (and will look into several later today), but the swing paths should be near identical...except, for a low shot, the follow-through is abbreviated (cut short to promote a low shot) and, for a high shot, the follow-through is fully executed  (to promote a high shot). A steeper angle of attack of the club on the golf ball would promote more backspin, which would promote a higher ball flight, but I'm going more for the fundamental of having your follow-through dictate the ball flight of your shot.
Comment: @hhh Added videos. I hope this helps you understand what I am trying to say.
Answer: The follow-through, in itself, has no bearing on the shot shape, especially with irons when you tend to tee the ball further back in your stance; for those shots, the ball is long gone before the clubhead begins to rise out of the turf. However, the mentality inherent in adopting a particular follow-through can cause a player to adopt certain changes in swing mechanics that do affect the portions of the swing prior to impact.
For instance, a mentality to abbreviate your follow through will cause you to lead more with your hands so you can control the club, and you'll feel like you're not "breaking" your wrist to release the clubhead until after the ball's already gone. In reality, you end up releasing the clubhead just before impact, so your hands are still a little out in front, de-lofting the club at impact. You also do one or two other things; keeping your hands in front means there's more distance between your hands and the ball at impact, and that can cause you to hit the ball "thinner", toward the bottom edge of the clubface, which causes a lower launch. Or, the additional bracing of your arms in anticipation of controlling the follow-through will cause you to stand up slightly on the downswing, and that also causes a thinner, lower-launch shot.
By contrast, focusing on taking a relaxed, full swing and follow-through will lead you to release the clubhead earlier, so the clubhead's inline with your head and hands at impact. That decreases the distance between your hands and the ball so you hit higher up on the clubhead, and lofts the club a little more, both causing a higher launch.


Expectation of a random variable and the indicator random variable proof

Question: I need to show that $E[T 1_A] = E[T|A]P(A)$.
What I've got so far is $E[T1_A] = \int_{\Omega}T.1_A dP = \int_AT dP$.
Now I know that $\int_AdP = P(A)$ however I'm lost as to how do I get the conditional probability?
Edit: Forgot to mention that T is a $Z_+$ random variable
Comment: Oftentimes the first relationship you have written is taken as the definition of $E[X \mid A]$. What conditional expectations have you defined?
Comment: If this is a homework question, you should use the homework tag. That way, people will know to give you a hint and not the full answer.
Comment: Hint: Multiply and divide by $P(A)$ the integral you have arrived at.
Answer: As commented above, it is common to define
$$
E[X\mid A]:=E[XI_A]/P(A),
$$
whenever $P(A)>0$, in which case there is nothing to prove. But one may also start with the standard measure theoretic definition of conditional expectation with respect to a $\sigma - $algebra and prove the following:

On the probability space $\left( \Omega, \mathcal F, P\right)$, for some event $A$ such that $P(A)\in (0,1)$, let $$\mathcal G := \sigma(A)=\{A, A^C, \Omega, \emptyset\}$$ and $X$ be an integrable random variable. Then $E(X\mid \mathcal G)=E[XI_A]/P(A)$ for every $\omega \in A$. The same holds for $A$ replaced by $A^C$.

Proof outline.  Recall the definition of conditional expectation: $\eta:=E[X\mid \mathcal G]$ is a (any) random variable such that $EI_B\eta=EI_BX, \forall B\in\mathcal G$. One may check that
$$
\zeta := I_AE[XI_A]/P(A)+I_{A^C}E[XI_A^C]/P(A^C)
$$
satisfies this definition. Thus, we may take $E[X\mid A]$ to mean the value of $E[X \mid \mathcal G]=\zeta$ on the set $A$ and have agreement with the definition in the first passage. I have left the details out due to the homework nature of this question.


How to set default output path `site-cookbooks` when using `knife cookbook create`

Question: Is there way to set default output path cookbooks to site-cookbooks when I run knife cookbook create?
I wrote cookbook_path in ~/.chef/knife.rb like this.
cookbook_path ['./site-cookbooks']

But this doesn't change default cookbook output path.
Answer: File expansion can be wonky in Ruby sometimes. If your site-cookbooks directory is at ~/site-cookbooks, then you could put in something like this in your knife.rb:
current_dir = File.dirname(__FILE__)
cookbook_path ["#{current_dir}/../site-cookbooks"]

Comment: Do you have multiple knife.rb files? Do you have multiple cookbook_path lines in your knife.rb?
Comment: I changed `knife.rb` setting as you wrote, but when I run `knife cookbook create something`, the receipt is created at `cookbook` as before, not in `site-cookbooks`. Am I missing something?
Comment: Great! That was the problem. I only changed my home directory knife.rb , but there is also in my current chef repository that I didn't notice.


Powershell: How to silently run an Outlook 2010 Rule?

Question: I would like to make a Powershell script that runs an Outlook2010 rule.  The same question was asked at the below URL; however, there was no solution at the time.
social.technet.microsoft.com/Forums
If there's a way to do this in C# or VBScript, I dont mind going that route; as long as there's some kind of feasible solution.
Answer: Server-side rules are applied to messages before they are delivered.
If I had to do this, I'd use Powershell and the EWS managed API, and script going through the Inbox items and emulating whatever that rule does with the email.
Comment: You can't "run the rule".  You have to reproduce (in your script) whatever it was the rule would have done.
Comment: Thanks.  I'm not very experienced with C# coding yet.  Could you be a bit more specific on how on how to do this?  The API seems to desbribe basic rule manipulation: listing, creating, modifying, and deleting rules (which I can already do via the microsoft.office.interop.outlook assembly).  If someone could please help me get started, I'd really appreciate it!
Comment: Have a look at some of the examples on Glen Scales blog: http://gsexdev.blogspot.com
Comment: I already did when searching via google earlier today. I didn't see any examples in that blog showing how to run a rule; especially via powershell... It seems like all the example I see show how create, modify, remove rules. not actually run them.


From C to Python

Question: I'm really sorry if this is a lame question, but I think this may potentially help others making the same transition from C to Python. I have a program that I started writing in C, but I think it's best if I did it in Python because it just makes my life a lot easier.
My program retrieves intraday stock data from Yahoo! Finance and stores it inside of a struct. Since I'm so used to programming in C I generally try to do things the hard way. What I want to know is what's the most "Pythonesque" way of storing the data into an organized fashion. I was thinking an array of tuples?
Here's a bit of my C program.
// Parses intraday stock quote data from a Yahoo! Finance .csv file.
void parse_intraday_data(struct intraday_data *d, char *path)
{
    char cur_line[100];
    char *csv_value;
    int i;

    FILE *data_file = fopen(path, "r");

    if (data_file == NULL)
    {
        perror("Error opening file.");
        return;
    }

    // Ignore the first 15 lines.
    for (i = 0; i < 15; i++)
        fgets(cur_line, 100, data_file);

    i = 0;

    while (fgets(cur_line, 100, data_file) != NULL) {
        csv_value = strtok(cur_line, ",");
        csv_value = strtok(NULL, ",");
        d->close[i] = atof(csv_value);

        csv_value = strtok(NULL, ",");
        d->high[i] = atof(csv_value);

        csv_value = strtok(NULL, ",");
        d->low[i] = atof(csv_value);

        csv_value = strtok(NULL, ",");
        d->open[i] = atof(csv_value);

        csv_value = strtok(NULL, "\n");
        d->volume[i] = atoi(csv_value);

        i++;
    }

    d->close[i] = 0;
    d->high[i] = 0;
    d->low[i] = 0;
    d->open[i] = 0;
    d->volume[i] = 0;
    d->count = i - 1;
    i = 0;

    fclose(data_file);
}

So far my Python program retrieves the data like this.
response = urllib2.urlopen('https://www.google.com/finance/getprices?i=' + interval +     '&p=' + period + 'd&f=d,o,h,l,c,v&df=cpct&q=' + ticker)

Question is, what's the best or most elegant way of storing this data in Python?
Comment: So youre using Yahoo's Finance API? In your code example you are using google's finance API, which no longer exists.
Comment: What does your struct look like?
Comment: @Alex Works just fine for me. ;-)
Comment: Yeah, the Google Finance method still works although the site says it no longer exists.
Answer: Keep it simple. Read the line, split it by commas, and store the values inside a (named)tuple. That's pretty close to using a struct in C.
If your program gets more elaborate it might (!) make sense to replace the tuple by a class, but not immediately.
Here's an outline:
from collections import namedtuple
IntradayData = namedtuple('IntradayData',
        ['close', 'high', 'low', 'open', 'volume', 'count'])

response = urllib2.urlopen('https://www.google.com/finance/getprices?q=AAPL')
result=response.read().split('\n')
result = result[15 :] # Your code does this, too. Not sure why.

all_data = []
for i, data in enumerate(x):
    if data == '': continue
    c, h, l, o, v, _ = map(float, data.split(','))
    all_data.append(IntradayData(c, h, l, o, v, i))

Comment: Thanks for the suggestion. Yeah, in the first snippet of code I was extracting data from a Yahoo! Finance csv file which begins with 15 lines that aren't actual data.
Answer: I believe it depends on how much data manipulation you will want to do after retrieving data.
If, for example, you plan to just print them on the screen then an array of tuple would do.
However, if you need to be able to sort, search, and other kind of data manipulation I believe a custom class could help: you would then work with a list (or even a home-brew container) of custom objects, allowing you for easily adding custom methods, based on your need.
Note that this is just my opinion, and I'm not an advanced Python developer.
Answer: Pandas (http://pandas.pydata.org/pandas-docs/stable/) is particularly well suited to this. Numpy is a little lower level, but may also suit your purposes. I really recommend going the pandas route, though. Either way you shouldn't lose too much of C's speed, so that's a plus.

From C to Python


grep the result of cdrecord or wodim

Question: I would like to parse the result/progress of a running cdrecord -v burn process. What I tried so far was cdrecord -v dev=/dev/sr0 -data foo.iso 2>&1 | grep -E 'Track [0-9]+:.*written'.
Unfortunately, the command above won't show anything until the burning is completed. I think this is due to the fact that cdrecord/wodim uses a carriage return (CR) in order to show the progress in the same line.
At the end of the burning process, only the following line is shown:
Track 01: Total bytes read/written: 98211840/98211840 (47955 sectors).

Is there any way to grep this kind of information?
Any hint appreciated!
Answer: tr did the trick!
cdrecord -v dev=/dev/sr0 -data foo.iso 2>&1 | tr '\r' '\n' | grep -E 'Track [0-9]+:.*written'

grep the result of cdrecord or wodim


Multiple threads in a for-loop using a parameterized function(x, y, z)

Question: I have a list which contains folder ID's and folder paths. I would like to pass some of these folders to a function which zips them.  What I want is to have three threads run in parallel and zip three different paths at a time. What happens now is each thread waits until the next one has finished in order to process the next. Any ideas?
Dim SelectedRange = From folders In listFolders Where folders.FolderID >= 150101

For Each item In SelectedRange
    Dim t As New Thread(
        Sub()
            Me.BeginInvoke(DirectCast(Sub() ZipFolder(sInclearDestination, item.FolderID.ToString, item.FolderPath), MethodInvoker))
        End Sub)
    t.Start()
    t.Join()
Next

Public Function ZipFolder(ByVal sFolderPathDestination As String, ByVal folderID As String, ByVal folderPath As String) As Boolean
    Try
        Using zip = New Ionic.Zip.ZipFile()
            'If the zip file does not exist then get the folder and zip it to the destination
            If Not File.Exists(Path.Combine(sFolderPathDestination, folderID & ".zip")) Then
                zip.AddDirectory(folderPath)
                zip.Save(Path.Combine(sFolderPathDestination, CType(folderID, String) & ".zip"))
                Return True
            Else
                Logging.Log("Aborting zipping: " & Path.Combine(sFolderPathDestination, folderID & ".zip") & ". The zip file already exists!")
                Return False
            End If
        End Using
    Catch ex As Exception
        Logging.Log("Error in zipping: " & Path.Combine(sFolderPathDestination, folderID & ".zip") & " Error: " & ex.Message)
        Return False
    End Try
End Function

Answer: There are two problems with your code.
The first problem is the call to Me.BeginInvoke.  Presumably you are creating a WinForm application and Me is a reference to the current Form.  The Form.BeginInvoke (inherited from the base Control class) causes the given delegate to be executed on the UI thread.  So, all you are doing is creating three separate threads which all immediately invoke back to the UI thread to do all of their work.  You obviously can't do that and still expect the tasks to be processed in parallel.  You need to remove the call to BeginInvoke.  If you need to call BeginInvoke in-order to update the display of some data on the form, you need to do it as late as possible and do as little work as possible within that UI-invoked code so that the majority of the work is still being done in the worker threads.
The second problem is the call to Thread.Join.  You are calling Join inside your For loop right after starting the thread.  That means that it will sit there and wait, at that call to Join, until the worker thread is complete.  Therefore, your loop waits for each thread to complete before starting the next one, in essence, making it single threaded.  You should just remove the call to Join.  If you need the calling method to wait for all the threads to complete, just wait to call Join on the threads until all of them have been started (i.e. after the For loop).
Comment: Oh, right.  I missed that.  That makes sense.  The `Join` was causing the calling thread to wait until the worker thread finished before starting the next one.  Sorry about that.  No, as long as that zipping library is thread-safe, there should be no problems.  You definitely should not have been calling `Join` there, as it wouldn't ever make sense to do that.
Comment: Well, you could do a `For i  = 1 To 3` loop and call `Joins` on all three threads after starting all three.  Then have an outer loop that keeps doing that until the list has been completely processed.  Or, the more simple solution is to use the `ThreadPool` class to start your threads.  That's the whole purpose of it.
Comment: I have changed it to the following but it's still zipping one at a time...  Dim t As New Thread(Sub()
                                    ZipFolder(sInclearDestination, item.FolderID.ToString, item.FolderPath)
                                End Sub)
Comment: Does the `ZipFolder` method, inside of itself, ever invoke to the UI thread?
Comment: No. I will post my zipFolder function on the question.
Comment: All that looks ok.  If it's still not running in parallel, then it's quite possible that the `Ionic.Zip.ZipFile` class uses `SyncLock`, or some similar mechanism, to stop multiple threads from writing to the same file at the same time.  I'm not familiar with that library, so I couldn't say for sure, but it seems like a likely thing for it to do.
Comment: By the way, how do you know that they aren't being done in parallel?  Via breakpoints, or some other method?
Comment: When I removed the "t.join" the zips started all together. (I'm not good with multithreading). Would this cause any problems?
Comment: I have accepted your answer. If you add the above comment it would make the answer better.
Comment: Steven, how would I ensure that only 3 threads run concurrently instead of having x number of threads executing something that drains the memory of the pc?


Learning mathematical concepts

Question: Our teacher loves to test us on pure concept based questions and test if we really know what we are doing when learning a particular lesson.
For example, when we first started learning about trigonometric identities, he once put a question on a test that was something along the lines of $$\sin18 \theta = \frac12$$
Looking back on this question now, it's extremely simple, but at the time of the test, I was perplexed because I had never seen this question before and never ran into it.
I understand what is going on in school and never fail to do my homework, but always end up missing one or two questions on the tests that pertain to pure conceptual questions that we have never seen before.
My question is: How can I prevent making this sorts of conceptual errors on these tests when running into them. Is there a website or certain textbook I can refer to, or some exercises I can do, in order to prepare for this sort of conceptual testing?
Comment: why do you consider this to be extremely simple?
Comment: @LearningMath This was the first lesson taught in the beginning of the year. Since then, I've reflected on question $sin18\theta = \frac12$ and I know how to solve it now. The question I have is for future math problems and concepts, not this one. I was just giving an example.
Comment: Is the class trigonometry? What are you currently learning in class?
Comment: This is an advanced trigonometry/pre-calculus class. It covers all of trigonometry (identities, polar equations, etc) as well as pre-calculus (parametric equations, sequences and series, limits, derivatives, etc).
Answer: As someone who is mostly self-taught and your age, my advice is you must first get comfortable with abstraction and proofs. You should be arguing with your teacher either mentally or verbally. I built up a great relationship with my trigonometry teacher this way because he welcomed my pressing curiosity, although there is no guarantee this can work for you.
I assume you do hold some mathematical curiosity (after all you're on Stack Exchange and your other questions suggest so), so a good place to start is with your current textbook. Skim the chapter ahead of time for certain theorems, and become adept at reading the theorem and proof. Exercises can only improve the time at which you work. So if time is an issue, then you should do the exercises before the test. Also, although Wikipedia and sometimes Google are frowned upon, they are usu. good sources to read. MIT OpenCourseWare and Khan Academy as well. Over the course of learning, you will learn what it means to cleverly manipulate equations rather than do procedural math, do your own rigorous proofs (besides simple algebraic derivations), and to ask and answer many questions to arrive at a solution.
Most importantly however is that you model whatever schedule to yourself. I don't force myself to do what I consider banal and boring. I may study math for 3-11 hours per day, but I do so because I enjoy it. And hey, what you might think to be boring might not be after you see some potentially cool connections.

Learning mathematical concepts


Como igualar um vetor vindo de uma matriz com uma matriz na função principal?

Question: Preciso igualar uma matriz que está retornando de uma função a uma matriz na função principal. Meu objetivo com isso é poder passar essa mesma matriz como parâmetro para outras funções sem precisar ficar chamando a função na hora de enviar a matriz.
Exemplo:
// função para retirar os espaços digitados
int retira_espaco(int tamanho, char vetor[], int t, char retorno []){
    int i = 0;
    int contador = 0;
    for (i=0; i<tamanho && vetor[i] != 0; i++){ //Nesse 'for' tem que se verificar se  vetor[i] !=0 pois o fgets sempre adiciona um 0 binario no final do que foi digitado
        if (isdigit(vetor[i]) || vetor[i] == 'i' || vetor[i] == 'p'
       || vetor[i] == '+' || vetor[i] == '-' || vetor[i] == '*'
       || vetor[i] == '/' || vetor[i] == '^' || vetor[i] == '='){
            retorno[contador++] = vetor[i];
        }
    }
    retorno[contador] = '\0';
    return (retorno);
}

Na hora de enviar os parâmetros para essa primeira função tenho que fazer da seguinte forma:
int main(){
    printf("%s\n", retira_espaco(tamanho, vetor, tamanho, retorno));
}

Quero então igualar uma matriz na função principal a matriz que retorna do retira_espaço, como proceder?
Comment: Olá. Bem vindo ao SOPT. Se não fez ainda, faça o [tour] e leia [ask]. Não entendi a sua dúvida. O que significa "igualar uma matriz"? Igualar a que? Também não entendi o que a sua função deveria fazer (o retorno de um valor inteiro com o índice de onde supostamente há um `+` ou um `-`, que não é uma matriz, não tem nada a ver com o que o nome da função diz que ela faz).
Comment: Perdão,amigo, inseri uma função diferente e não tinha percebido, agora concertei.
O que eu quero igualar é a matriz retorno com uma matriz na função principal. Normalmente para igualar matrizes se usa
     for ( i = 0; i<10; i++){
           matriz[i] = retorno[i];
     }
só que como não sei como fazer isso quando a matriz retorno, como no caso, está vindo de uma função.
Comment: Eu retirei o voto pra fechar. Mas ainda assim, não está totalmente claro. Vc quer comparar o conteúdo de `retorno`, *após a chamada de `retira_espaco`*, com alguma outra matriz, é isso? Esse exemplo que você postou não compara, e sim atribui. O `=` único é diferente do `==` duplo de comparação.
Comment: Exato, porque assim eu consigo utilizar a matriz retorno dentro da função principal sem precisar ficar chamando ela toda hora.
Comment: @Miguel Goffredo, o que você quer eu já entendi. Basicamente, quer alterar a matriz (vetor por ter tamanho 1 em umas das dimensões) que passou para a função. Quer que a matriz que passou seja alterada para ter o novo conteúdo retornado. Editei sua pergunta para melhorar o texto, deixar com o visual mais convidativo, arrumar erros e adicionar "*tags*" que serão pertinentes. Já estou para responder a ti.
Comment: @José não editaste nada ;)
Comment: @JorgeB. eu editei mas como tiverem duas pessoas com edição aguardando aprovação do mesmo conteúdo (você, no caso), o que eu editei se perdeu.
Comment: @José mas tem de estar no histórico mesmo assim, e eu não vejo nada. Estranho...
Comment: @JorgeB. é verdade; não está no histórico! E eu havia editado a resposta para facilitar o entendimento! Mas basicamente o colega quer alterar a matriz original com o que foi feito na função.
Answer: O que você está querendo fazer é atribuir o array retorno que foi preenchido pela função retira_espaco para um outro array, mas isto é desnecessário, porque os arrays são passados por "referência" quando são usados como parâmetros de funções. Isto é, o array retorno dentro da função retira_espaco é o mesmo array de fora da função que foi passado como parâmetro.
Exemplificando
char x[100], y[100];

// ...outros comandos

// o array "retorno" dentro de retira_espaco na verdade e' o array y aqui de fora
retira_espaco(100, x, 100, y);

printf("%s", y);

Agora, sua função retira_espaco está erradamente declarada como int retira_espaco, deveria ser void retira_espaco. Além disso não está usando o 3º parâmetro t, e aquele comando final return (retorno) é desnecessário e na verdade errado, só faria sentido se o tipo da função fosse char *.
Além disso, seu exemplo printf("%s\n", retira_espaco(tamanho, vetor, tamanho, retorno));está errado, pois o formato %s é para strings (char*), e você declarou a função retira_espaco como int.
Answer: Vejamos...
A melhor forma de lidar com seu problema é usar a idéia de passagem por referência dos argumentos. E isso cai naquela nuvem negra de ponteiros - mas que é fácil depois que domina!
Se quiser ler sobre ponteiros, eu indico este material da USP. É curto, conciso e fácil de entender. Também indico esta pergunta do Stack Overflow em inglês se dominar o idioma.
Solucionando o problema
Tomando como verdade o código que você forneceu e deixando-o enxuto para o propósito de exemplificação, o que poderia ser feito é o seguinte:
#include <stdio.h>
#include <string.h>
#include <ctype.h>

void retira_espaco( char * vetor ){

  int i, j, tamanho;

  tamanho = strlen( vetor );

  for ( i = 0; ( i < tamanho ) && ( vetor[i] != 0 ); i++ ){

    if( isdigit( vetor[i] ) || vetor[i] == 'i' || vetor[i] == 'p' || vetor[i] == '+' || vetor[i] == '-' || vetor[i] == '*' || vetor[i] == '/' || vetor[i] == '^' || vetor[i] == '=') {

      /* Movimenta para posteriores posições para dentro, eliminando caracteres desejados */
      for( j = i; j < (tamanho - 1); j++ ) vetor[j] = vetor[j+1];
      vetor[ tamanho - 1 ] = '\0';

      /* Por conta do movimento acima, precisa-se checar a posição atual novamente */
      --i;

    }

  }

}

int main( void ){

  char vetor[] = "abcdef+=efghijklmnopq/xyz";

  retira_espaco( vetor );

  printf( "Resultado: %s\n", vetor );

  return( 0 );

}

O resultado obtido é satisfatório:
Resultado: abcdefefghjklmnoqxyz

Explicando
Se você cria um ponteiro - imagino que saiba o que é um ponteiro ou que leu o artigo recomendado - como parâmetro para a função (exemplo: char * vetor), você poderá passar sua matriz vetor como referência para a função - ou seja, não passasse o valor e sim o endereço de memória do mesmo. Isso significa que poderá modificar o conteúdo da matriz original.
O que aqui foi feito é simples:

criou-se a função que modifica a matriz: void retira_espaco( char * vetor ){...}
passou-se, por referência, uma matriz pré-determinada para ser modificada: retira_espaco( vetor );
verificou-se se a modificação ocorreu: printf( "Resultado: %s\n", vetor );

Note que vetores passamos por referência por padrão. Se fosse um vetor alocado, usaríamos o operador & para referênciar. Exemplo:

a função ficaria: void retira_espaco( char ** vetor ){...}
a declaração da matriz em main() ficaria: char **vetor = malloc(...);
a passagem por referência ficaria: retira_espaco( &vetor );

Desta forma, poder-se-ia não só manter os valores bem como também modificar o tamanho de memória alocada. Com alocação dinâmica de memória, ao invés de preencher com '\0', se obteria uma matriz de tamanho apropriado e com menor consumo de memória. Porém, é um pouco mais trabalhoso e foge ao escopo de apresentação do tema.


Price History for each item in database

Question: I have this table
Transactions
- id
- user_id // this will point to which user did this transaction
- item_id // this will point to which item in this transaction
- date

Products
- id
- name

Items
- id
- product_id // this will point to which product this item is
- name
- price

The problem is, overtime, the item's price will change.
To prevent changes in the old transaction history's price
I need a way to keep old item's price.
How can I make the right database design to solve this?
Comment: Maybe just save price to the transaction?
Answer: You need to add this info on the Transaction:
Transaction
 - id
 - user_id
 - item_id
 - item_price
 - any_other_transaction_specific_info

This also lets you apply discounts or any other modifications on the actual price for each transaction.
Answer: Its better to save price current product price when transaction is done in transaction table with a price column.

Transactions
- id
- user_id // this will point to which user did this transaction
- item_id // this will point to which item in this transaction
- date
- price
Answer: I think you can define a date for each transaction record. on the other hand, you can have another table for recording the product price priceLogs.(like: product_id, price and date). anytime a product's price is changed, a record is added to the table. this will also help you in some more business issues for tracking the price of products.
you need to query the price of each product based on the date of transactions. This might make you write a bit of joins in your query.
Answer: In my opinion you should instead create another table as Item_Pricing and this should help you finalize the pricing history. The table Item_Pricing history should be like this Item_Pricing(id[PK], itm_id[FK], price, price_still_in_use, date_price_created,...). The idea is that the colum price_still_in_use should be considered as a flag that can have value 1(yes) or 0(no). Then in your table transaction this is the price that should be considered. Then each transaction or sale should relate to the pricing that still in use as followed :
Transactions
(id[PK],...,item_pricing_id[FK] // this will point to Item_Pricing(item_pricing_id), quantity, date)
So if the item price changes in your application the price of the item should no longer be available if no longer used. A trigger might also help you for best results so that the same item can't have more than one price that has the value yes for the column(attribute) price_still_in_use

Price History for each item in database


How do i fix this error i'm getting "Sorry, the page you are looking for could not be found."

Question: I have this application where I am trying to get the the author of a question to be able to mark an answer as the best answer.
I have an AcceptAnswerController created which has been registered in the routes/web.php file as below:
AcceptAnswerController.php
class AcceptAnswerController extends Controller
{
    public function __invoke(Answer $answer)
    {
        $this->authorize('accept', $answer);

        $answer->question->acceptBestAnswer($answer);
        return back();
    }
}

web.php
Route::get('/', function () {
    return view('welcome');
});

Auth::routes();

Route::get('/home', 'HomeController@index')->name('home');

Route::resource('questions', 'QuestionsController')->except('show');

Route::resource('questions.answers', 'AnswersController')->only(['store', 'edit', 'update', 'destroy']);

Route::get('questions/{slug}', 'QuestionsController@show')->name('questions.show');

Route::post('answers/{answer}/accept', 'AcceptAnswerController')->name('answers.accept');

In my Answers view, i have the following:

{{ $answersCount . " " . str_plural('Answer', $answersCount) }}

                @include ('layouts._messages')

                @foreach ($answers as $answer)

                            1230

                            @can ('accept', $answer)
                                status }} mt-2"
                                    onclick="event.preventDefault(); document.getElementById('answer-{{ $answer->id }}').submit();"
                                    >

                                <form id="answer-{{ $answer->id }}" action="{{ route('answers.accept', ['answer' => $answer->id]) }}" method="POST" style="display:none;">
                                    @csrf
                                </form>
                            @else
                                @if ($answer->is_best)
                                    status }} mt-2"
                                        >

                                @endif
                            @endcan

                            {!! $answer->body_html !!}

                                        @can ('update', $answer)
                                             $question->id, 'answer' => $answer->id]) }}" class="btn btn-sm btn-outline-info">Edit
                                        @endcan
                                        @can ('delete', $answer)
                                            <form class="form-delete" method="post" action="{{ route('questions.answers.destroy', [$question->id, $answer->id]) }}">
                                                @method('DELETE')
                                                @csrf
                                                <button type="submit" class="btn btn-sm btn-outline-danger" onclick="return confirm('Are you sure?')">Delete</button>
                                            </form>
                                        @endcan

                                    Answered {{ $answer->created_date }}

                                        user->url }}" class="pr-2">
                                            user->avatar }}">

                                            user->url }}">{{ $answer->user->name }}

                @endforeach

Once the author of the question clicks on the check icon, it should mark the answer as the best answer but i get the following error:
Sorry, the page you are looking for could not be found
I see that the answer id is missing in the url as follows:

http://localhost:8000/answers//accept

when it should actually be something like this:

http://localhost:8000/answers/1/accept

I can't seem to figure out why as i passed it as a route parameter in the form action. Same thing happens if a user is trying to edit his answer.
Answer: Can I suggest tweaking your strategy a little bit here and bypassing the need for a form submission?
If you swap out the POST for a GET request, this is actually pretty straight forward.
Answers.blade.php
@foreach( $answers as $answer )
    @can('accept', $answer)
        id }}/accept" title="Mark this answer as best answer" class="{{ $answer->status }} mt-2">

    @else

Do your thing

    @endcan
@endforeach

routes.web.php
Route::get('answers/{answer}/accept', 'AcceptAnswerController');

Answer: So, after scrutinizing my code a bit more carefully everything else seemed okay the controller, routes, views. I was able to isolate the problem down to this region
@can ('accept', $answer)
 status }} mt-2"
  onclick="event.preventDefault(); document.getElementById('answer-{{ $answer->id }}').submit();"
                                   >

 <form id="answer-{{ $answer->id }}" action="{{ route('answers.accept', ['answer' => $answer->id]) }}" method="POST" style="display:none;">
     @csrf
 </form>
@endcan

I was certian the $answer->id was supposed to return the correct id but i wasn't too sure  about the $answer->status so I decided to check its accessor defined in the Answer model.
public function getStatusAttribute()
{
   return $this->isBest() ? 'vote-accepted' : '';
}

public function isBest()
{
   return $this->id = $this->question->best_answer_id; /** here is the problem **/
}

There the problem was staring right back at me. The isBest method above was supposed to return a boolean value but i was mistakingly assigning. This was the simple fix.
public function isBest()
{
   return $this->id === $this->question->best_answer_id; /** here is the problem **/
}


Chords behaving as a melody

Question: I've been learning some Christmas carols on the guitar and I noticed  that the chord structure they have is very different from what I can  usually see in popular/rock music.
I noticed that the melody that is meant to be sung is reflected (along with it's pitch) by the chords following this melody.
That  feels like the chords don't function here as an accompaniment to a  melody and does not provide it's standard function, which is tension and  release, but rather follow the sung word changing to match higher or  lower pitch that is currently being sung.
So  instead of chords being its own thing and melody its own (in a  reasonable, consonant way, of course), the chords seem to be the melody  itself. If you didn't sing the song and just played the chords, you  could pretty much imagine the right words In your head.
It feels different than a typical chord progression I'd sing a song along with.
Is there a name for these two approaches of composing?
And  more importantly, what would we call the function of these chords that  follows the melody by it's pitch more than by a sense of building  release and tension? Are they for an accompaniment, or sometimes maybe  it's just ok to follow the melody with chords pitch like and by the  function they stand for in the scale?
The video (it's a tutorial in Polish, it's a Polish Christmas carol):

I'm  talking about this exact moment (chords changing rapidly trying to match the singing voice) and pretty much entire song in general.  The song starts with V (Gmaj) and I believe the entire song is in C so it's  already pretty unusual from a popular music point of view to start a  song from V chord.
And that's what I mean by "more popular approach to chords accompanying melody":
Comment: This reminds me of SATB choir/hymn, where 4 voices can generate a specific chord (meaning that the chord is the melody itself).
Comment: Oh, that's interesting. So as far as I can see I could harmonise the song in two approaches: One would be with standard chord strumming pattern and the other is with chords following the melody, right?
Answer: If I'm understanding the question correctly, it sounds like you are describing what is called appropriately enough, "Chord Melody" which is a popular method to harmonize a melody line often seen in jazz arrangements, but can be used in almost any style of popular music. I'm guessing you got your hands on some of those kind of arrangements, but I can assure you that Christmas carols can be played and sung using the more common chords and separate melody lines also. That said, it generally takes more skill to play "Chord Melody" so it's not used as often.
Comment: @Duplex It's just generally hard to play that many different chords to do the whole melody. It's generally easier to play and hold one chord (with a strumming pattern) while you sing until you get to the next chord.
Comment: Ok, got it. Why though is it harder to play chord melody? Is this because you have to think of chords in terms of pitch (following the melody) and not their harmonical function?
Comment: @ Duplex- Actually, I'm not an advanced Chord melody kind of player, but I'd say it doesn't exclude the first idea in favor of the second idea, but rather including both ideas together while choosing the best voicings of each chord to help harmonize the chord note selected to carry the melody. When I've done it, I've had to work up arrangements of the music and rehearse what I had worked up before ever thinking about performing the piece. Contrast that with playing something where the leader says " we're going to do this one in "A". More chord changes too.
Comment: It might be good to point out that it is possible to play the verses of a song using the simpler method and then play a lead break using some chord melody. Mix and Match is perfectly acceptable and even advisable if one is just starting to learn the technique.
Answer: I'm not certain if this is what you're after, but you may be interested in the concept of the melodic-harmonic divorce in rock music. In short, it's a theory about this repertoire that states that a melody and its underlying harmonies don't always work in tandem the way they traditionally did (like, for instance, in a Christmas Carol), with dissonant pitches often not resolving the way our ears may expect. (If you're interested, you can read more about this phenomenon in this famous article.)
I don't know the history of the Christmas Carol (see also What exactly is a Christmas carol?), but I wonder if these tunes originally began as unaccompanied melodies. If the harmony was added later, it may help explain why it so closely follows the melody.
Comment: I haven't heard the word "divorce" before, but I think it describes modern pop music very well. Melody and harmony have divorced and they live their separate lives. Melody sticks with the minor/major pentatonic scale and avoids making any commitments or statements about any specific harmony. The chords behind the melody can be pretty much anything. Lyrics are made by the lyrics committee, harmony by the chords committee, and melody by the melody committee. Proper rhythm and EDM sounds from a suitable vendor. Calculate earnings and costs, record company board approves the business decision.
Comment: Thank you for the links. Actually what you wrote in the last sentence about carols being unaccompanied melodies at first makes a lot of sense (because they are old songs). Maybe this is why the chord structure follows them so closely.

However I believe there could be another way of accompaniemnt for this carol I provided, right? Like the one (chord progression) that would be more static, providing some harmonical function beside just following the melody.

I tried accompanying this song by myself before and I might try to do it later.

Chords behaving as a melody


How to use sed to find a path and concatenate the output with a string

Question: I would like to add a string to a sed output to form the complete path, I am not sure how I can concatenate the string to the result, how should I modify the following command? Any help would be appreciated.
$ go env | grep GOPATH | sed 's/.*="\(.*\)"/\1/'

/Users/Paul/go

# Would like to add /bin/hello to the above path with the end result
/Users/Paul/go/bin/hello

Comment: Any time you're considering using grep+sed or sed+sed you should either be using a single call to sed or a single call to awk instead, depending on the operation you're trying to perform. if you [edit] your question ti include a [mcve] with concise, testable sample input (the output of `go env`) and expected output then we can help you.
Answer: You could do this in a single awk itself. My go env output has GOPATH like GOPATH="/root/go" so I have taken care of " part here, new values will be added before last " by awk.
go env |  awk '/GOPATH/{gsub(/^GOPATH="|"$/,"");$0=$0 "/bin/hello";print;exit}'

2nd solution: Using sed you could try following here. Stop printing of lines by -n option of sed and print only matching line which has GOPATH in it, along with new values attached to it.
go env | sed -n '/GOPATH/ s|.*="\(.*\)"|\1/bin/hello|p'


What are some ways to normalize variables to compare standard deviations?

Question: I have a list of time-series variables which are all in different scales. The variables are not normally distributed and some values are negative. What are some ways to normalize these variables so that I can compare their standard deviations?
I thought about normalizing by the average of each variables. What are some other ways?
Comment: Could you explain what a comparison of standard deviations of any kind of *normalized* values would mean? What are you hoping it could tell you?
Comment: Hi Whuber, I wish to find the variable which gives me the lowest standard deviation.
Comment: Then pick the smallest standard deviation! What is the purpose of normalizing?
Comment: the levels for the time series are different.
Comment: Now we're going around in circles--It's impossible to tell what you're actually looking for, apart from the impression you want to measure something about the spread of the data.  Let me end this conversation, then, just by pointing out that [the answer you have accepted](http://stats.stackexchange.com/a/164131) does not address this. By comparing the SD to some other estimate of spread, such as the range, IQR, or MAD, you would actually be getting some information about the *shape* of the distribution, but *not* about any actual measure of spread of the data.
Answer: simply use coefficient of variation which is SD/mean.
Comment: Coefficient of variation is useless when some values can be negative.
Comment: This answer is potentially a valid response to the original question, but would be *much* better if it compared some of the pros and cons of using the coefficient of variation.
Comment: But my variables are not very close to normal distribution. Would this bias the final standard deviation in some way?
Answer: You can't normalize by the average when some values can be negative. For example:
-20, -10, 0, 10, 20
now, add 20 and multiply by 10:
0, 100, 200, 300, 400
The first set has mean of 0, so if you normalize by the mean, you get infinity.
One alternative is to normalize by the range or some variation of it, such as the interquartile range.  ALso, instead of the standard deviation, you might want to use the MAD (median absolute deviation) if the variables are very non-normal.
Comment: [The comment by @silverfish](http://stats.stackexchange.com/questions/164123/what-are-some-ways-to-normalize-variables-to-compare-standard-deviations#comment312068_164129) applies here, too: what exactly would a comparison of SDs mean after carrying out any such normalization? What would be the pros and cons of the three approaches you describe?


Block all incoming trafic to VBox guest VM, except ESTABLISHED and RELATED

Question: I have host machine, which is running Virtualbox and one guest VM. Let's say host have interface br0 with IP 188.8.131.52 and guest have eth0 with IP 126.96.36.199.
Guest is using 188.8.131.52 as public IP (bridged interface, via br0 on host). I want it to be able to access Internet, but want to completely block all attempts to access it from outside. It is not serving anything, it could be completely blocked out of the Internet, if not the fact that it need to download a thing or two from time to time...
How to do that on the host, without impacting host? Not on the guest, on the host. I want host to be accessible from the outside world, from the Internet. But guest should only receive packets that are related to connections established by the guest. No ssh login attempts, nothing initiated from outside (I know, I can use other tools to secure the guest also, like sshd_config on guest, and I use them but I want to use iptables also).
I tried blocking everything related to the guest first and then work my way up to excluding RELATED and ESTABLISHED, but even if I add DROP rules with 188.8.131.52 as source and destination to all chains on host (INPUT, FORWARD, OUTPUT), I can still ping 126.96.36.199 from outside world. What am I doing wrong? Yes, I added those rules in the beginning of chains (-I). iptables behave differently when I am doing it on a host and traffic is destined to the virtual machine/guest? Or is it because I use bridge br0?
So I am not even able to DROP everything coming from and to 220.127.116.11 (IP that is on the guest VM) even though tcpdump on a host shows 126.96.36.199 as source and destination when I run it to intercept ICMP packets, while I ping 188.8.131.52 from outside world.
Answer: Although you can manipulate traffic going through the bridge, I'm not sure you can do connection tracking (RELATED/ESTABLISHED).
The place to do it would be the FORWARD chain.
What does sysctl -a|grep -E "bridge-nf-call-ip.*tables" give you? If you set, for instance, net.bridge.bridge-nf-call-iptables to 1, and do iptables -P FORWARD DROP, the guest should no longer have internet. You can take it from there and see if you can more.
Comment: I actually have no idea if that influences things. Experimentation would be required.
Comment: That sysctl with a grep returned nothing. I had to load `br_netfilter` kernel module (it is CentOS 7). Now I have: `net.bridge.bridge-nf-call-ip6tables = 1`,
`net.bridge.bridge-nf-call-iptables = 1`. But dropping everything on FORWARD chain still does nothing for the guest. It can be pinged from outside world. Don't know if it changes anything, but I am using Vagrant to manage VirtualBox machine. Probably do not change much.
Comment: Ok, there is one thing that I failed to mention and maybe that's why I can not do that. The host itself is a KVM virtual machine. I am using nested virtualization. So there is "master host", on which there is a KVM machine, the one that I call "a host" and then on that KVM machine is VirtualBox "guest".

I guess that it might be too complicated to be worth debugging. I will probably close this question. The "host" is also using bridge on "master host" to access network.

Sorry for failing to mention that.
Comment: So to sum things up, I didn't knew about br_netfilter and in normal circumstances that would probably solve things and I would be able to block traffic via FORWARD chain. In my case it is not working because of complications of my environment that I did not mention in original question. That's why I am marking this answer as a solution.


Is a git repo as html content safe?

Question: I've been searching with a couple different terms but didn't find exactly what I was looking for.
I got the idea to start a blog with a flat file CMS. It would be handy to have the pages in a git repository, so I can easily update the blog from anywhere and have it automatically update with webhook. The question is, could I safely, just clone and pull the changes to the public content on the server? Or should I rather clone it to some un-published folder and copy the files to the public contents?
I think about using Grav for the CMS, btw.
Answer: Safe enough. There's CMS systems out there that already do this, such as Jekyll.
Comment: Let me ask you this instead: what negatives do you see to it that would make it not a good practice?
Comment: That's kind of where I got the idea from. I'm still not sure if it's good practice to do so though. It's just a hobby project, anyway, but I still don't want to employ bad practice just because it's easy and popular ;-)
Comment: Thinking about it like that I can't see any particular reason. It just feels weird to have a quasi public folder directly linked to a repository. It's a gut-feeling I'd say.

Is a git repo as html content safe?