Apply different filters after main MultiMatch query in Elastic Search NEST

Question: So, this is my query:
_elasticClient.Search<SearchItem>(x =>
                x.Sort(sort).Size(itemsPerPage)
                .Query(q =>
                    q.MultiMatch(m => m
                    .Fields(fs => fs
                        .Field(p => p.Field1)
                        .Field(p => p.Field2)
                        .Field(p => p.Field3)
                        .Field(p => p.Field4)
                        .Field(p => p.Field5)
                        .Field(p => p.Field6)
                    )
                    .Operator(Operator.And)
                    .Query(pattern)
                )));

I have to apply different filters. Range filters (for price), filter result set where field1 = "Audi" and field2 = "Sale Car". I tried to do something like that:
.Query(q =>
                    q.MultiMatch(m => m
                    .Fields(fs => fs
                        Field(p => p.Field1)
                            .Field(p => p.Field2)
                            .Field(p => p.Field3)
                            .Field(p => p.Field4)
                            .Field(p => p.Field5)
                            .Field(p => p.Field6)
                    )
                    .Operator(Operator.And)
                    .Query(pattern)))
.Query(q=>q.Range(ra=>ra.Field(ff=>ff.SalePrice).GreaterThan(1000))));

But this is not working. I've all results from the index with price greater then 1000, but need only searched results. Could anyone help me?
Comment: Use a `bool` query to combine both the `multi_match` and the `range` query - https://www.elastic.co/guide/en/elasticsearch/client/net-api/2.x/bool-queries.html
Answer: You can use a bool query to combine queries and NEST makes this slightly easier to work with by overloading operators to combine QueryContainers (the root query type). Here's an example for NEST 2.x
void Main()
{
    var connectionPool = new SingleNodeConnectionPool(new Uri("http://localhost:9200"));
    var settings = new ConnectionSettings(connectionPool);

    var client = new ElasticClient(settings);

    var itemsPerPage = 20;
    var pattern = "match query";

    client.Search<SearchItem>(x => x
        .Sort(so => so
            .Descending("_score")
        )
        .Size(itemsPerPage)
        .Query(q => q
            .MultiMatch(m => m
                .Fields(fs => fs
                    .Field(p => p.Field1)
                    .Field(p => p.Field2)
                    .Field(p => p.Field3)
                    .Field(p => p.Field4)
                    .Field(p => p.Field5)
                    .Field(p => p.Field6)
                )
                .Operator(Operator.And)
                .Query(pattern)
            ) && q
            .Range(ra => ra
                .Field(ff=>ff.SalePrice)
                .GreaterThan(1000)
            )
        )
    );
}

public class SearchItem
{
    public int SalePrice { get; set; }

    public string Field1 { get; set; }

    public string Field2 { get; set; }

    public string Field3 { get; set; }

    public string Field4 { get; set; }

    public string Field5 { get; set; }

    public string Field6 { get; set; }
}

which yields
{
  "size": 20,
  "sort": [
    {
      "_score": {
        "order": "desc"
      }
    }
  ],
  "query": {
    "bool": {
      "must": [
        {
          "multi_match": {
            "query": "match query",
            "operator": "and",
            "fields": [
              "field1",
              "field2",
              "field3",
              "field4",
              "field5",
              "field6"
            ]
          }
        },
        {
          "range": {
            "salePrice": {
              "gt": 1000.0
            }
          }
        }
      ]
    }
  }
}

This will find documents that are a match for the multi_match query and also have a salePrice greater than 1000. Since we don't need a score calculated for the range query (a document either has a salePrice greater than 1000 or it doesn't), the range query can run in a filter context. A slightly refined version
client.Search<SearchItem>(x => x
    .Sort(so => so
        .Descending("_score")
    )
    .Size(itemsPerPage)
    .Query(q => q
        .MultiMatch(m => m
            .Fields(fs => fs
                .Field(p => p.Field1)
                .Field(p => p.Field2)
                .Field(p => p.Field3)
                .Field(p => p.Field4)
                .Field(p => p.Field5)
                .Field(p => p.Field6)
            )
            .Operator(Operator.And)
            .Query(pattern)
        ) && +q
        .Range(ra => ra
            .Field(ff=>ff.SalePrice)
            .GreaterThan(1000)
        )
    )
);

appending the unary + operator to the range query is a shorthand for a bool query filter. The query json now looks like
{
  "size": 20,
  "sort": [
    {
      "_score": {
        "order": "desc"
      }
    }
  ],
  "query": {
    "bool": {
      "must": [
        {
          "multi_match": {
            "query": "match query",
            "operator": "and",
            "fields": [
              "field1",
              "field2",
              "field3",
              "field4",
              "field5",
              "field6"
            ]
          }
        }
      ],
      "filter": [
        {
          "range": {
            "salePrice": {
              "gt": 1000.0
            }
          }
        }
      ]
    }
  }
}


Unit testing rendered Json with JsonBuilder in Grails

Question: Let's say I have a simple action in my controller that ends with:
render(contentType: "text/json") {
    message = 'some text'
    foo = 'bar'
}

It renders correctly, as per the JSON builder documentation.  However, when I attempt to unit test that response in a ControllerUnitTest, I get a blank string with controller.response.contentAsString.  I even tried controller.renderArgs, but that just contains contentType: "text/json".
When I convert the JSON to a map, and marshall it as JSON, then I can test properly.  But is there a way to unit test the code as it stands?
Answer: you have to call the action in your tests and compare the results using controller.response.contentAsString
so your test method would look like
void testSomeRender() {
controller.someRender()
assertEquals "jsonString", controller.response.contentAsString

}

Comment: I've tried this, but like I mentioned, I just get a blank string (or it contains "contentType: 'text/json'", I can't remember off the top of my head)
Comment: I just added a code for an action which return the JSON string like you are trying to do and I don't see any content. So the issue is with content not being rendered. What version of Grails are you using ?
Comment: 1.3.7, I know 2.0 has better support, but unfortunately I can't switch to that. :-\
Comment: 1.3.7 is a stable release than 2.0. 2.3 wasn't suppose to be out till oct and they are already out with the bug fixes. I think that the JSON convertor doesn't convert any String objects to JSON and hence its returning empty string. One thing which I tried was created a Expando Object and added properties to it and then rendered it and it worked. I think you should try that. Hope that helps
Answer: After much searching, I found that this is not possible in 1.3.7.  Either have to upgrade to Grails 2.0, or override the controller metaClass as suggested in this post:
controller.class.metaClass.render = { Map map, Closure c ->
    renderArgs.putAll(map)

    switch(map["contentType"]) {
        case null:
            break

        case "application/xml":
        case "text/xml":
            def b = new StreamingMarkupBuilder()
            if (map["encoding"]) b.encoding = map["encoding"]

            def writable = b.bind(c)
            delegate.response.outputStream << writable
            break

        case "text/json":
            new JSonBuilder(delegate.response).json(c)
            break
        default:
            println "Nothing"
            break
    }
}

Answer: Take a look at this blog post http://www.lucasward.net/2011/03/grails-testing-issue-when-rendering-as.html
Comment: Broken link, 404.


Why won't collectstatic copy my static files?

Question: I have a MyApp/static/MyApp directory.
When I run ./manage.py collectstatic, I expect the MyApp directory be copied to STATIC_ROOT, but it doesn't.
I have DownloadedApp/static/DownloadedApp as well and its copied to STATIC_ROOT fine.
What am I missing?
Answer: What are the STATIC_ROOT, STATICFILES_FINDERS, and STATICFILES_DIRS in your settings.py?
When collectstatic is run, the default STATICFILES_FINDERS value django.contrib.staticfiles.finders.FileSystemFinder will collect your static files from any paths that you have in STATICFILES_DIRS.
The other default STATICFILES_FINDERS value django.contrib.staticfiles.finders.AppDirectoriesFinder will look in the /static/ folder of any apps in your INSTALLED_APPS.
All of the static files that are found will be placed in the specified STATIC_ROOT directory.
Check out this link to the collectstatic docs
And this link an explanation of the various static settings in settings.py
You can also use python manage.py findstatic to see which directories collectstatic will look in.
Comment: `python manage.py findstatic` renders `Error: Enter at least one static file.`
Comment: @antonagestam `python manage.py findstatic -v 3 dummy` will output the paths after the error.
Comment: django cached static_root static_url settings.py won't reflect the change I made in file.
Answer: That just happened to me and I accidentally put the app's static files directory in the .gitignore file.  So on my local machine it got collected just fine, but in production the static files were actually missing (gitignored).
Comment: @lysdexia you have to differentiate between an app's static files folder and the project's static files folder.  When you run ``collectstatic`` it copies the individual apps' static folders into the project's static folder.  If you gitignored your app's static folder it doesn't get pushed into the production environment and hence doesn't get collected.
Comment: This makes no sense to me: doesn't collectstatic create those directories when it's run? I'm having the same problem (over and over, for different reasons, it seems)
Comment: This happened to me, but in Heroku, in the `.slugignore` file instead of the  `.gitignore`
Comment: Happened to me )) Thanks for saving my time!
Answer: just do this and make the naming convention same
STATIC_URL = '/static/'
STATICFILES_DIRS = [
    os.path.join(BASE_DIR, 'static')
]
STATIC_ROOT = os.path.join(BASE_DIR, 'assets')

static directory contains all off your project assets
assets directory will create automatic when u run this cmd
python3 manage.py collectstatic

this will copy all static folder content into assets folder
hope this helps :)
Comment: I followed the exact same steps, but it has not copied the files in assets folder
Answer: your are missing the STATIC_ROOT where your static files going to be copied just
add this line in your settings.py
STATIC_ROOT=os.path.join(BASE_DIR,'staticfiles')

your settings.py looks like this :
STATIC_URL = '/static/'
STATIC_ROOT=os.path.join(BASE_DIR,'staticfiles')

#added manully
STATICFILES_DIRS = [
   os.path.join(BASE_DIR, "static")

]

remember to add STAIC_ROOT path in urls.py
from django.contrib import admin
from django.urls import path, include
from django.conf import settings
from django.conf.urls.static import static

urlpatterns = [
    path('admin/', admin.site.urls),
    path("" ,include("home.urls")),

]+static(settings.STATIC_URL, document_root=settings.STATIC_ROOT)

After all of it you can run :
python manage.py collectstatic

it will create a staticfiles folder for you in your Dir
Answer: This happened to me because while investigating a bug occurring on certain dates, changed my computer date and time.
Hence it disturbed things like collectstatic, and also my browser history.
Don't change your computer date and time.
Answer: I was under the impression the comparison would be content based. It turned out to be date based. So, don't mess with your files after collecstatic.
Answer: One Quick work-around, although this does not fix it or explain WHY it's happening, is to:

go to your project's file directory & rename your project's
'static' folder to something else like 'static-old'
create a new,empty folder called 'static' in your project directory
now if you run python manage.py collectstatic it will see that nothing is
in your static folder and will copy ALL static files over.
Answer: if you have setup everything properly for static and you are using nginx then enter this command
sudo nginx -t

You will see error why your static files aren't being served and fix that specific error
In my case I gave wrong path in my nginx config
location /static {
        root /home/ubuntu/myproject/app/static/;
    }


Display paragraphs items in comma-seperated series

Question: I have a series of paragraphs items representing two different types of contributors to a publication: staff (user link) and non-staff (text).  (See How to control the display of a user account connected via entity reference)
According to Paragraphs preprocess paragraphs handles building the render array for its items in the same way as nodes, comments, etc, so maybe my question is much broader, but here's what I'm trying to do:
I want to send up with a basic comma separated list of items:
Person 1
or
Person 1 and Person 3
or
Person 1, Person 2, and Person 3
with links on the items that should be links.  I guess I just am not getting render arrays and the theming functions well enough yet, that I understand how to do it.
The paragraphs preprocess question makes me think maybe I should be overriding the fields_formatter, but what I've been working on up to this point is theme_preprocess_paragraphs_items().  That seems like it should allow me to do what I want, I can see that I could loop through $variables['element']['#items'] or maybe the integer keys of $variables['element'], but how to change those so that they append ', ' or ', and ' or whatever as appropriate (outside of the link on link items is escaping me).  (I do understand how to determine what should be appended, just not where to append it to make drupal output what I want.
Answer:
append ', ' or ', and ' or whatever as appropriate

You can use CSS to accomplish this
HTML

    Editor:

            Person 1

            Person 2

            Person 3

            Person 4

      Author:

                  Person 4

    Translator:

            Person 5

            Person 6

CSS
.paragraphs-items { /* start each field on a new line*/
    clear: left;
}

.paragraphs-items div { /* eliminate the blocky results of div hell (eliminate some extra spacing in the process)*/
    float: left;
}

.paragraphs-items .entity-paragraphs-item .content:after { /* default to putting commas after every value … */
    content: ", ";
}

.paragraphs-items .entity-paragraphs-item:last-child .content:after { /* … except the last one */
    content: "";
}

.paragraphs-items .entity-paragraphs-item:nth-last-child(2) .content:after { /* The last two items in the series should be separated by a ", and " … */
    content: ", and ";
}

.paragraphs-items .entity-paragraphs-item:nth-last-child(2):nth-child(2) .content:after { /* … unless there are only two items, in which case it should be " and " */
    content: " and ";
}

EXAMPLE DEMO
Note in content: ", " since it won't pick up the empty space (by pressing the space bar) I used the ALT+0160 trick to make the empty space.


Como tornar um projeto de público para privado no GitHub?

Question: Tenho um projeto público na conta gratuita, tem como torná-lo privado?
Comment: Achei a pergunta suficientemente aceitável para a comunidade, não vi justificativas para a pergunta ter 4 votos negativos. Alguém que votou poderia justificar?
Comment: @HiagoSouza Mas é sobre repositórios e GitHub, ferramentas cotidianas para o desenvolvedor previstas no [4º item desta lista](https://pt.meta.stackoverflow.com/q/264/5878).
Comment: @AndersonCarlosWoss você tem razão! Desculpem o equivoco, vou modificar o voto para positivo.
Comment: @AndersonCarlosWoss a pergunta não é sobre programação, não é um erro e não caracteriza uma dúvida sobre programação. Posso ter me equivocado, mas no meu entendimento, não pertence ao site. Caso esteja errado, me avise que eu modifico o voto.
Answer:
Basta ir às configurações do seu repositório, clicando em "Settings":

Em seguida, procure a seção "Danger zone", no final da página de configurações:

Ao clicar no botão "Make private" (tornar privado), você possivelmente precisará confirmar a sua senha. Após isso, o seu repositório estará privado.
Answer: Guia github e mais informação, relevante sobre a informação e features que perde/ganha de acordo com a visibilidade:
Configurando a visibilidade do repositório.

No GitHub, para a página principal do repositório.
Sobre o nome do repositório, clicar em Configurações.
Sobre a "Zona de Alerta", próximo do Tornar este repositório privado, clicar em Tornar privado.
Ler os avisos sobre tornar um projeto privado.
Introduzir o nome do repositório que quer tornar privado, por exemplo, accountname/reponame.
Clicar em Compreendo, tornar este repositório privado.
Answer: Tem sim!
Escolha o seu projeto, vá em configurações do seu projeto, no fim da página tem uma opção Tornar Privado.


Execute jquery functions in order

Question: function fn_one() {
   $('#search-city-form').trigger('click');
}

function fn_two() {
   $("form input[name='tariffId']").val("137");
   $('#search-city-form').trigger('click');
}

function fn_three() {
   $("form input[name='tariffId']").val("138");
   $('#search-city-form').trigger('click');
}

function fn_four() {
   $("form input[name='tariffId']").val("139");
   $('#search-city-form').trigger('click');
}

$(document).on('click','.ui-menu li',function(){

        fn_one();

        fn_two();

        fn_three();

        fn_four();
    });

I have this js code. I need to execute the functions in on(click) in order, i.e. fn_one() goes first, fn_two() second and etc.
Please give simple example of how can I achieve this.
Edit: OK, I used the next function to be executed in the previous one but still I was getting erraneous data. So I think I realized why this is happening. I will explain what $('#search-city-form').trigger('click'); does. It triggers a form submit which makes an Ajax call and other function are not waiting till ajax request is complete. So how do I make it to wait for ajax request to complete?
EDIT 2:
Event handler for $('#search-city-form'):
            $('#cdek').submit(function() {

            var formData = form2js('cdek', '.', true, function(node) {
                if(node.id && node.id.match(/callbackTest/)) {
                    return {
                        name : node.id,
                        value : node.innerHTML
                    };
                }
            });
            var formDataJson = JSON.stringify(formData);
            // console.log(JSON.stringify(formData));
            document.getElementById('testArea').innerHTML = 'Отправляемые данные:
' + JSON.stringify(formData, null, '\t');

            $.ajax({
                url : 'http://api.cdek.ru/calculator/calculate_price_by_jsonp.php',
                jsonp : 'callback',
                data : {
                    "json" : formDataJson
                },
                type : 'GET',
                dataType : "jsonp",
                success : function(data) {
                        console.log(data.result.price);
                    } else {
                        for(var key in data["error"]) {
                            console.log(data["error"][key]);
                        }
                    }
                }
            });
            return false;
        });

Comment: won't this end up in an infinite loop due to there is a click handler on `document` which executes further click events?
Comment: According to that code, they are being executed in order.
Comment: @messerbill no, this is event delegation on `ui-menu li`
Comment: To be sure about the order, you can execute the functions as callbacks. That way, the 2nd will start only when the first one ends, etc…
Comment: Already executed in order. Use the next function to be executed in previous function. For Example. Call `fn_two` at the end of `fn_one()`. SetTimeout if you want any delay in calling
Comment: @Ele and a click on a HTML Element (like  here) is not a click on `document` at the same time?
Comment: do you want a time delay between the calls?
Comment: they are in order. check here > http://jsfiddle.net/q1ft25pn/39/ look in console . But you can nest them if you want as others have suggested.
@messerbill the ideea is that it doesn't work as you first suggested. So for eg if there is another div, and click on it, it won't trigger the click on the `ui-menu li` . So clicking anywhere except the `event delegation` won't work
Comment: What does the `$('#search-city-form').trigger('click');` do? If I understand well, when you click on `.ui-menu li` you trigger the click on `$('#search-city-form')`, then change your `$("form input[name='tariffId']")` value, then trigger click again, change value again, trigger click, change value and trigger click again?
Comment: This is totally unclear, Please post a [Minimal, Complete, and Verifiable example](https://stackoverflow.com/help/mcve)
 to understand a little more your scenario.
Comment: ok, but in my opinion this will be executed synchronously anyway (because there are no "async calls" anywhere in the code)
Comment: @messerbill yes, you're right.
Comment: what happens when you run the code as is, does it throw any errors or you don't see the functions executing in the right order?
Comment: @messerbill please see the edit
Comment: @MickaelLeger please check the edit.
Comment: @Ele please check the edit.
Comment: Possible duplicate of [Access result of previous promise inside a second](https://stackoverflow.com/questions/49137143/access-result-of-previous-promise-inside-a-second)
Comment: so far we are talking about `Ajax` calls this is a dupe
Comment: Now, everything is clear!
Comment: 1.) Can you share the event handler of `search-city-form`. 2.) Why are you triggering that process (ajax call) using `.trigger('click')`?
Comment: @Ele 1)Please check EDIT 2. 2)I want to emulate form submission where ajax call is made.
Answer: I'll do this. If you need validate when the function has triggered, maybe you need to work with promises.

    function fn_one() {
   $('#search-city-form').trigger('click');
   fn_two()
}

function fn_two() {
   $("form input[name='tariffId']").val("137");
   $('#search-city-form').trigger('click');
    fn_three()
}

function fn_three() {
   $("form input[name='tariffId']").val("138");
   $('#search-city-form').trigger('click');
   fn_four()
}

function fn_four() {
   $("form input[name='tariffId']").val("139");
   $('#search-city-form').trigger('click');
}

$(document).on('click','.ui-menu li',function(){

        fn_one();
    });

Execute jquery functions in order


How can I close all dataframes that I've opened using the variable explorer?

Question: In the process of writing code using python and pandas, I have opened many dataframes to inspect their contents by double clicking on their object names in the variable explorer. I was wondering if there is an option to "Close all", instead of "X"-ing out of each one individually.
Answer: (Spyder maintainer here) Unfortunately this is not possible at the moment, sorry.


Cant get libraries to compile cloud endpoints python

Question: class Patient(EndpointsModel):
    user = EndpointsUserProperty(required=True, raise_unauthorized=True)
    date_of_birth = EndpointsDateProperty()
    age = ndb.IntegerProperty()

    def calculate_age(self):
        today = date.today()
        birthday = self.date_of_birth
        self.age = today.year - birthday.year - ((today.month, today.day) < (birthday.month , birthday.day))

    def _pre_put_hook(self):
        if self.date_of_birth:
            self.calculate_age()

....
api_root = endpoints.api(name='ffsapi', version='vGDL',
                    description='API for whole app')

@api_root.api_class(resource_name="patient")
class PatientApi(remote.Service):

    @Patient.method(
                    request_fields=('name', 'date_of_birth'),
                    name='insert',
                    path='patient',
                    http_method='POST')
    def insert_patient(self,patient):
        if patient.date_of_birth: # TODO find a better way
            if patient.date_of_birth.year <1900:
                raise endpoints.BadRequestException('date <= 1900')
        patient.put()
        return patient

    @Patient.query_method(user_required=True,
                          query_fields=['name'],
                          name='query',
                          path='patient')
    def query_patient(self,query):
        return query
....
application = endpoints.api_server([api_root], restricted=False)

This is my file when I run endpointscfg.py it tells me that it is not a ProtoRPC service. I have tried application,api_root,and ffsapi. The code deploys fine works fine just can't get the compiling of libraries to work.
Here is the yaml file if that helps
application: ******(im just hiding it)
version: 1
runtime: python27
api_version: 1
threadsafe: yes

handlers:
- url: /favicon\.ico
  static_files: favicon.ico
  upload: favicon\.ico

- url: .*
  script: main.application

# Endpoints handler
- url: /_ah/spi/.*
  script: main.application

libraries:
- name: webapp2
  version: "2.5.2"
# Needed for endpoints/users_id_token.py.
- name: pycrypto
  version: "2.6"
- name: endpoints
  version: 1.0

Answer: In this case, because you're only implementing the API with one class, you should decorate the PatientApi class with the @endpoints.api decorator instead of calling endpoints.api() separately and assigning the result to a variable. Then, you'd create the API server with:
application = endpoints.api_server([PatientApi], restricted=False)
Finally, to generate the Open API specification using endpointscfg.py, you'd pass in main.PatientApi (assuming your source file is called main.py).


Get codebehind to create a complete JS section

Question: I want my codebehind to dump a very large set of JS into the ASPX page. This is required, as I can't use external JS code for this component, and the code is also unique to each customer. Is it possible to do this from codebehind? I know how to set the value of text boxes etc. (.Text/.Value = xxx) but I can't see how I can just 'dump' code straight onto the page.
Answer: have a look at Page.ClientScripts.RegisterStartupScriptBlock or RegisterScriptBlock, these method do exactly what you need.
Comment: This should do the trick. I recommend using StringBuilder to build your large javascript string - it is much more efficient that concatenations when doing lots of string appending.
Answer: Try using RegisterClientScript:
http://www.codeproject.com/KB/aspnet/Register_Client_Script.aspx
Answer: set a string variable into code behind and then add to the page just
<%= variableName %>

where you want your js code to be dumped to
Or if you like you can create a method and do the same thing
<%= methodName() %>


Prove that R is an integral domain

Question: I'm studying for my qualifying exam and I came across the following question in one of the old question bank.

Consider the affine space given by four $2\times 2$ matrices, i.e., $\mathbb{A}^{16}\cong M(\mathbb{C})_{2\times 2}^4$. Now, consider the algebraic set $V$ given by the vanishing of the relation $AB-CD=0$, where the matrices are as follows: $A=(a_{ij}), B=(b_{ij}), C=(c_{ij})$ and $D=(d_{ij})$. Prove that $V$ is irreducible in $\mathbb{A}^{16}$.

In other words, I want to prove that the following ring

$R=\mathbb{C}[a_{11},a_{12},a_{21},a_{22}, b_{11},\dotsc, d_{21},d_{22}]/I$, where $I=(a_{11}b_{11}+a_{12}b_{21}−c_{11}d_{11}−c_{12}d_{21},\,a_{11}b_{12}+
a_{12}b_{22}−c_{11}d_{12}−c_{12}d_{22},\,a_{21}b_{11}+a_{22}b_{21}−c_{21}d_{11}−c_{22}d_{21},\,a_{21}b_{12}+a_{22}b_{22}−c_{21}d_{12}−c_{22}d_{22})$

$R$ is an integral domain.
I've been trying to follow the same idea as in this post (https://math.stackexchange.com/a/4303220/884739), but I'm having hard time trying to figure out what the correct change of coordinate should be, so that I can embed this ring $R$ inside some field and hence, conclude that $R$ is an integral domain.
Comment: I would check if the subset with $\det(ABCD)\ne 0$ is dense (the complex topology makes it easy: if $f$ vanishes on $W=V\cap \det(ABCD)\ne 0$ then it vanishes on the whole $V$), as it is clear that $W$ is irreducible
Comment: @Pierre-GuyPlamondon because the above ring can be seen as the coordinate ring of the representation space of the quiver which looks like a   commutative diagram, with dimension vector $(2,2,2,2)$.
Comment: Why is the tag "quiver" applied to this question?
Answer: You can consider $V'$ the open subset of $V$ given by the non-vanishing of the polynomial $a_{1,1}a_{2,2}-a_{1,2}a_{2,1}$. $V'$ is defined by the relations $$
\det A \neq 0, $$ $$ B = A^{-1}CD.
$$ The second of these expresses the variables $b_{1,1}, b_{1,2}, b_{2,1}, b_{2,2}$ in terms of the remaining $12$, which implies that the (restriction to $V'$ of the) projection onto $V(a_{1,1}a_{2,2}-a_{1,2}a_{2,1})^c \subseteq \mathbb{A}^{12}$ is an isomorphism of varieties, the latter being irreducible (it shouldn't be hard to see the polynomial $(xy-zw)t - 1$ is irreducible).
To finish, all you have to do is check that $V'$ is Zariski-dense in $V$, which amounts to showing the canonical map $$
\mathbb{C}[a_{1,1}, \dots , d_{2,2}]/I := R \to R[(a_{1,1}a_{2,2}-a_{1,2}a_{2,1})^{-1}]
$$is injective (or rather, that its kernel equals the nilradial, which I guess might not be trivial a priori?).
To find this kernel we search for polynomials $p$ in $\mathbb{C}[a_{1,1}, \dots, d_{2,2}]$ such that $d^k\cdot p \in I$ for some $k\geq 0$, where $d := a_{1,1}a_{2,2}-a_{1,2}a_{2,1} $. We may also suppose $p$ to be homogeneous since $I$ and $d$ both are (whence the considered kernel will also be). I think you can now compare leading terms and work out that $k=1$; this shouldn't be a tough computation using that $p$ is homogeneous.
I think this last step can be made more direct by arguing that your generating system for $I$ is a grobner basis, by computing the $S$-polynomials, but I'm not sure you're allowed to use those in your exam :p
Best of luck! I hope this was helpful and I didn't make any silly mistakes :)
P.s. I'd love to see a solution using quiver representations as you remarked!
Comment: The idea is that- you consider the quiver that I mentioned in the comment and then, consider the representation which is given by the $Id_{2\times 2}$ at all the four arrows. Now, you can prove that the representation space is equal to the closure of the orbit of this representation and hence, the ring $R$ is an integral domain.
Comment: Sounds cool! I think this amounts to showing the open subset where $A,B,C$ and $D$ are all invertible is dense in $V$, since this is the orbit you mention if I'm not mistaken. I like this description of the problem much better :)

Prove that R is an integral domain


Python, como validar se a variável é None?

Question: Não estou conseguindo verificar se a variável não possui valor (None)
View:
endereco_id = request.POST.get('endereco_id', None)
if formCliente.is_valid() and formEndereco.is_valid():
    print('********** endereco_id **************')
    print(endereco_id)
    print('************************')
    if endereco_id:
       formEndereco.instance= Endereco.objects.get(id=endereco_id)

O print:
********** endereco_id **************
None
************************

Por que está entrando no IF se no print o valor da variável é None?
Tentativas:
if endereco_id != None:
     formEndereco.instance= Endereco.objects.get(id=endereco_id)

if endereco_id is not None:
     formEndereco.instance= Endereco.objects.get(id=endereco_id)

Nada funcionou, onde estou errando? A versão do Python é a 3.5 com Django 1.10.
No Shell funciona:
>>> endereco_id=None
>>> if endereco_id:
...     print('Possui valor')
... else:
...     print('É None')
...
É None
>>> endereco_id=1
>>> if endereco_id:
...     print('Possui valor')
... else:
...     print('É None')
...
Possui valor
>>>

View:
def novo_cliente(request):

    formCliente = ClienteForm(request.POST or None)
    formEndereco = EnderecoForm(request.POST or None)

    if request.method == 'POST':
        cliente_id = request.POST.get('cliente_id', None)
        endereco_id = request.POST.get('endereco_id', None)

        if formCliente.is_valid() and formEndereco.is_valid():
            if endereco_id is not None:
                formEndereco.instance= Endereco.objects.get(id=endereco_id)

            if cliente_id is not None:
                formCliente.instance= Cliente.objects.get(id=cliente_id)

            novo_endereco = formEndereco.save()
            novo_cliente = formCliente.save(commit=False)
            novo_cliente.endereco = novo_endereco
            novo_cliente.save()

            return redirect('appOrcamento:edit_cliente', orcamento.id)

    context = {
        'formCliente':formCliente,
        'formEndereco':formEndereco,
        }

    return render(request, 'appOrcamento/novo_cliente.html', context)

Comment: Edilson, obrigado pela sugestão.  Mesmo a variável sendo None, entrou no else.
Comment: Sim, eu só incluí o else para testar a sua sugestão.  Eu realmente só tenho uma linha que deve ser processada caso o endereco_id seja diferente de None.
Comment: Edilson, eu já tentei com o is not None, porém não tive sucesso.  Mesmo a variável estando None, entra no if.  Fiz o mesmo teste no shell e funcionou.  Será que o erro é porque estou recuperando o valor do POST?  endereco_id = request.POST.get('endereco_id', None)
Comment: O código é extenso, caso não coloca-o no pastebin, ou outro repositório qualquer para que possa ver.
Comment: Coloquei o view na pergunta.
Comment: E qual seria o `else` aí ? Já usaste `if not defined_id` ou mesmo `if defined_id == None` ? Porque deve tudo retornar falso quando se usa com o `if`, seja None, False ou String vazia.
Comment: O else não existe.  Se o endereco_id possuir valor, preciso recuperar o endereco o mesmo acontece para o cliente_id.
Comment: Certo, já experimentaste os exemplos que apresentei neste último comentário ?
Comment: Vamos [continuar esta discussão no chat](http://chat.stackexchange.com/rooms/57137/discussion-between-developer-and-edilson).
Answer: Com ajuda do @Edilson, conseguimos identificar o problema.  É básico, porém para quem está iniciando em Python com Django, pode se tornar complicado.  Por este motivo vou explicar o que ocorreu.
Ao recuperar o valor de um campo no POST na view, caso o campo não exista no template o retorno é None, ou seja, não existe o campo, seria o null.  Quando o campo existe no template, mas se estiver sem informação o retorno no posto é um str 'None'.
Esse foi o meu problema, no print estava sendo impresso None, porém era do tipo str e o if não funcionava corretamente.
Ex.:
cliente_id = request.POST.get('cliente_id', None)
Caso cliente_id não exista  no template, o retorno será None (null)
Caso cliente_id exista no template, porém sem valor, o retorno será um str 'None'
A solução:
def novo_cliente(request):

    formCliente = ClienteForm(request.POST or None)
    formEndereco = EnderecoForm(request.POST or None)

    if request.method == 'POST':
        cliente_id = request.POST.get('cliente_id', None)
        endereco_id = request.POST.get('endereco_id', None)

        if formCliente.is_valid() and formEndereco.is_valid():
            if endereco_id != 'None':
                formEndereco.instance= Endereco.objects.get(id=endereco_id)

            if cliente_id != 'None':
                formCliente.instance= Cliente.objects.get(id=cliente_id)

            novo_endereco = formEndereco.save()
            novo_cliente = formCliente.save(commit=False)
            novo_cliente.endereco = novo_endereco
            novo_cliente.save()

            return redirect('appOrcamento:edit_cliente', orcamento.id)

    context = {
        'formCliente':formCliente,
        'formEndereco':formEndereco,
        }

    return render(request, 'appOrcamento/novo_cliente.html', context)

Espero que essa resposta possa ajudar aos iniciantes.
@Edilson, obrigado pela ajuda.
Comment: Legal que conseguiu resolver. Só lia quesão agora  -verificar se você não tinha um str com conteúdo "None" seria minha sugestão  - mas é um problema que pode pegar quem tem mais anos de casa também.  A dica que fica quando tiver outro mistério parecido é usar o `pdb` - você coloca um break-point no código com "`import pdb; pdb.set_trace()`" , submete o forumlário, e acompanha no debugger a execução linha a linha  - teria matado o problema na primeira sessão também.
Comment: @jsbueno, blza?  A dica do pdb é excelente, eu tentei usar, mas quando mando seguir o processamento ele gerava erro.  Ai fiquei na dureza do print.  O colega Edilson me sugeriu o type(), ai foi na mosca.  Perdemos um tempo, mas conseguimos.  Coloquei a resposta para ajudar a galera que está iniciando como eu.  Valeu pelo comentario, vou tentar usar o pdb novamente.  Agora eu te garanto, problemas com tipo de variáveis, nunca mais...rsrs


Oracle Sort Order - What may cause it to change

Question: Disclaimer: I know that it is bad to not use an 'ORDER BY' in SQL when sorted data is  required.
I am currently supporting a Pro*C program which is having a wierd-problem.
One of the possible causes of the wierd-problem may be that the original developers (from a long time ago) have not used ORDER BY in their SQL even though the program logic depends on it!
The program has been working fine all these years and started showing problems only recently.
We are trying to pin the wierd-problem to the ORDER BY mistake (there are other cause candidates like a recent port from Solaris to Linux which took place).
What shadowy things on the database end should we look at that may have changed the old sort order? Things like data files etc?
Anybody have any experience with Pro*C on Solaris magically sorting the result-set?
Thanks!
Answer: Since you know that the program cares about the order in which results are returned and you know that the query that is submitted is missing an ORDER BY clause, is there a reason that you don't just fix the problem rather than looking to try to figure out whether the actual order of results may have changed?  If you fix the known ORDER BY problem and the "weird problem" you have disappears, that would provide some pretty good evidence that the "weird problem" is, in fact, caused by the missing ORDER BY.
Unfortunately, there are lots of things that might have caused the order of results to change many of which may be impossible to track down.  The most obvious cause would be a change in the execution plan.  That, in turn, may have been caused either because statistics changed or because statistics didn't change enough or because of a patch or because of an initialization parameter change or because of a client configuration change among other things.  If you are licensed to use the AWR (Automatic Workload Repository), you might be able to find evidence that the plan has changed by looking to see if there are multiple PLAN_HASH_VALUE values for the SQL_ID in DBA_HIST_SQLSTAT over different days.  If there are, you'd still have to try to figure out whether the different plans actually caused the results to be returned in a different order.  Beyond a query plan change, though, there are dozens of other possible causes.  The physical order of data on disk may have changed because someone reorganized the table or because someone moved data files around on the disk or because the SAN automatically rebalanced something by moving data around.  Some data may have been cached (or may not have been cached) in general in the past that is now cached.  An Oracle patch may have been applied.
Comment: Thanks for your answer! I will research some more about AWR and Plans.
I have changed the code, but it will take a week to know if it fixed the problem. And it is tough telling users that the problem is still not solved a week later :(
Answer: I suggest that change your physical table with view and make your required order in that view.
example
TABLE_NOT_SORTED --> rename to --> PHYS_TABLE_NOT_SORTED
CREATE VIEW TABLE_NOT_SORTED
AS
SELECT * FROM PHYS_TABLE_NOT_SORTED
ORDER BY DESIRED_COLUMNS

For response to comment:
According to this question and Ask Tom's Answer, it seems that since Oracle does not guarantee a default sorting if you do not use "ORDER BY", they are free to change it. They are absolutely right of course. If you need sorting, use Order By.
Other than that we can not say anything about your code or default ordering.
Comment: There was no user intervention on the DB, no upgrades, no patches etc.
What I am looking for is, 'probable' causes like data files, partitions, etc from your past experience. (I say probable because I think this is not documented).
Comment: Yup, but the problem I am having is not in fixing it. I can add the ORDER BY to the program.
The problem is determining if I am fixing the right problem. To do that I need to check what has changed on the DB end which has caused the order to change.
Comment: Only you can tell what's happened on the DB @dvlpr, people here can only guess. For instance; have you recently upgraded it? Applied a patch? Changed some of the initialisation parameters?
Comment: It seems so, there is almost no results with search.


how to write this query correctly

Question: for each category show the equipment cheapest in this category
it was my attempts to solve it, however I don't know what to write further
SELECT category_of_equipment, name_of_equipment, price
from equipment
where price = ( select min(price)
from equipment

the table
CREATE TABLE equipment (
    id int NOT NULL,
    price int NOT NULL,
    name_of_equipment varchar(228) NOT NULL,
    category_of_equipment int NOT NULL,
    CONSTRAINT equipment_pk PRIMARY KEY (id)
);

Comment: Please share expected result you need to get from the query.
Comment: Please read https://stackoverflow.com/help/minimal-reproducible-example.
Answer: Rank equipment by price (partitioned by category) and return rows whose rank = 1.
That should be somewhat better than a correlated subquery because this option selects data from the equipment table only once, while correlated subquery has to select it twice (once in a subquery, and once again to return desired data).
WITH
   ranker
   AS
      (SELECT e.*,
              RANK ()
                 OVER (PARTITION BY category_of_equipment ORDER BY price ASC) rnk
         FROM equipment e)
SELECT r.id,
       r.price,
       r.name_of_equipment,
       r.category_of_equipment
  FROM ranker r
 WHERE r.rnk = 1;

Answer: You can use  a correlated subquery
select category_of_equipment, name_of_equipment, price
from equipment t
where price = ( select min(price)
                from equipment t2
                where t2.category_of_equipment = t.category_of_equipment);

Answer: You can use self join -
select
    a.*
from
equipment a JOIN
(
   select category_of_equipment,min(price) minPrice from equipment group by price
) b
where
a.category_of_equipment = b.category_of_equipment and a.price = b.minPrice

how to write this query correctly


Ativar evento do botão ao dar enter em um edit

Question: Criei uma tela de "cadastro" onde o usuário informa o nome/apelido e onde há um botão Continuar que vai para uma outra tela. Gostaria que essa nova tela fosse aberta quando o usuário apertasse a tecla Enter, porém não sei como fazer para a tecla Enter ter essa função.
Abaixo o código da tela inicial
public class CadastroActivity extends AppCompatActivity {

EditText edtNome;

Button btnContinuar;

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

    edtNome = (EditText) findViewById(R.id.edtNome);

    btnContinuar = (Button) findViewById(R.id.btnContinuar);

    btnContinuar.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            Intent EnviarDados = new Intent(CadastroActivity.this, ResultadoActivity.class);

            String txtNome = edtNome.getText().toString();

            Bundle bundle = new Bundle();

            bundle.putString("nome", txtNome);

            EnviarDados.putExtras(bundle);

            startActivity(EnviarDados);

        }
    });
}

}
Answer: A melhor prática para atingir isto que você quer é utilizar o evento setOnEditorActionListener do EditText como mostra esta resposta ou esta daqui.
Você vai precisar configurar o EditText no XML (caso não tenha feito) com o imeOptions correspondente a "próximo campo".
<EditText
    android:id="@+id/editText2"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:maxLines="1"
    android:imeOptions="actionNext" />

Note que aqui definimos a propriedade maxLines="1", que vai fazer com que o Android saiba que ao pressionar o Enter, deve-se avançar o campo. O android:imeOptions="actionNext" muda o desenho do botão "Enter" com uma seta, indicando para o usuário que ao clicar alí ele será levado para o próximo campo/tela/etc. Definir esta propriedade no XML também define a identificação do evento do Edit para que você possa executar a ação que deseja.
editText.setOnEditorActionListener(new TextView.OnEditorActionListener() {
    @Override
    public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
        if (actionId == EditorInfo.IME_ACTION_NEXT) {
            callAnotherActivity();
            return true;
        }
        return false;
    }
});

Comment: Essa seria minha sugestão. Não seria capaz de ir tão profundo por dificuldades técnicas minhas mesmo, de não ter aprofundado em Android, mas pela teoria rumores sugerir isso. E detalhe importante: nessa resposta, implicitamente a ação de chamar a outra atividade fiquei encapsulada em um método. Assim, essa chamada pode ser aproveitada para ser usado pelo botão também
Comment: Sim, a título de aprendizado coloquei o listener explícito. Mas poderia ter feito `editText.setOnEditorActionListener(this)`, fazer a Activity estender a interface `OnEditorActionListener` e fazer uma verificação do campo a ser validado com `v.equals(editText)`.


Pandas - problema na exclusão de uma linha

Question: Olá, estou com um problema na hora de excluir uma linha em uma tabela de um arquivo .xlsx
caminho_arquivo_excel = r'C:\Users\A3336228\Documents\CreditLimitReviewV3\Resources\Report\teste123.xlsx'

dados = pd.read_excel(caminho_arquivo_excel, header=None)

indice_pn = dados[dados[1] == 'PN'].index[0]

dados = dados.iloc[indice_pn:]

dados = dados.drop(columns=[4, 5, 11])

dados = dados.drop(columns=[0])

dados[14] = dados[14].replace('\.', '/', regex=True).fillna('')

dados = dados.drop(1)

dados = dados.drop_duplicates()

caminho_salvar_xls = r'C:\Users\A3336228\Documents\CreditLimitReviewV3\Resources\Report\UKM_BP_DISPLAY_QZJS_RPA.xlsx'

dados.to_excel(caminho_salvar_xls, index=False, header=False)

print("Planilha salva em:", caminho_salvar_xls)

quando eu uso o dados = dados.drop(1) (para excluir a linha 2 do arquivo), me é retornado o erro abaixo:
Erro axis
Abaixo está a tabela sem excluir a linha 2, estou tampando os valores pois sao valores sensiveis.
Tabela sem a linha 2 com valores sensiveis.
Alguém teria uma solução? Pois, já tentei especificar o índice e não funcionou de nada.
Abaixo está a tabela antes de entrar no drop linha 2.
antes de entrar no drop
Answer: Um de seus drops, não está bem especificado o que é para dropar, o dados = dados.drop(1), experimenta especificar melhor, usado axis e label. Como no exemplo abaixo:
import pandas as pd
import os

path_file = (os.path.realpath(os.curdir) + '\\Files\\Book.xlsx')

df = pd.read_excel(path_file)

print(df)

df = (df.drop(axis=0,labels=1))

print(df)


$F(x)=\sum_{n}^{\infty}\frac{1}{2^n}\chi_{[r_n, \infty)}$ is right continuous

Question:
Let $\left\{ r_n\right\}$ be enumeration of rational numbers. Prove
  (1) F is continuous from the right
  (2) F is continuous at $x$ if $x$ is irrational
  $$F(x)=\sum_{n}^{\infty}\frac{1}{2^n}\chi_{[r_n, \infty)}$$

I have  shown that $F$ is strictly increasing ($x < y \Rightarrow F(x)<F(y)$) and $F$ is bounded (in particular $F(-\infty)=0, \ F(+\infty)=1$).
I thought if I consider a sequence $(x_n)\searrow x$, then $F(x)< \cdots <F(x_2)<F(x_1)$ and monotone boundness tells us $F(x_n) \rightarrow F(x)=\inf_n\left\{ F(x_n)\right\}$, but I'm not sure about this.
Comment: What was your difficulty in using monotone convergence Theorem?
Comment: @BrevanEllefsen Similarly I can argue that $F$ is also left continuous then $F$ is continuous everywhere. Then it's none-sense to ask to prove (1), (2) separately.
Answer: For each $x\in\mathbb{R}$, denote the Dirac-measure associated with $x$ by $\delta_x$. That is, for any Borel set $A\subseteq\mathbb{R}$, $\delta_x(A) = 1$ if $x\in A$ and $\delta_x(A)=0$ if $x\not\in A$. Define $\mu = \sum_{n=1}^\infty \frac{1}{2^n} \delta_{r_n}$, which is a Borel measure. Then $F$ defined at the beginning is the cumulative distribution function associated with $\mu$. That is, $\mu( (-\infty, x]) = F(x)$. The right-continuity of $F$ follows from the general theory about the c.d.f. of a Borel measure.
To show that $F$ is the c.d.f. of $\mu$, let $x\in\mathbb{R}$. Then $\mu((-\infty, x]) = \sum_{n=1}^\infty \frac{1}{2^n} \delta_{r_n}( (-\infty,x])$. For each $n$, $\delta_{r_n}( (-\infty,x]) =1$ iff $r_n \in (-\infty,x]$ iff $r_n \leq x$ iff $x\in [r_n,\infty)$. Therefore $\chi_{[r_n,\infty)}(x)=\delta_{r_n}( (-\infty,x])$ and it follows that $\mu((-\infty, x]) = F(x)$.
To show that $F$ is continuous at $x$ if $x$ is irrational:
Let $x\in\mathbb{R}$ be an irrational number. Let $(x_n)$ be an aribrary sequence of real numbers such that $x_1<x_2<\ldots<x$ and $x_n\rightarrow x$. To show that $F$ is left-continuous at $x$, it suffices that $\lim_n F(x_n)=F(x)$ (Heine Theorem). Note that $F(x)-F(x_n) = \mu( (x_n,x] ) = \mu( (x_n, x) )$ because $\mu(\{x\})=0$ (as $x$ is irrational).
Note that $\{(x_n,x) \mid n\in\mathbb{N}\}$ is a decreasing sequence of Borel sets with $\bigcap_n (x_n,x) = \emptyset$. By continuity of measure, we have $\lim_n \mu( (x_n,x)) = \mu(\bigcap_n (x_n,x)) =0$. That is, $\lim_n F(x_n)=F(x)$.
Answer: You can directly use the definition of continuity.
Fix $x_0 \in \mathbb{R}$, we show $f$ is right-continuous at $x_0$. Given $\varepsilon > 0$, choose $\delta$ so small such that all $\{r_n\}$ in the interval $(x_0,x_0+\delta)$ satisfies $2^{-n} < \varepsilon$. When $x\in (x_0,x_0+\delta)$, we have
$$|F(x) - F(x_0) | = \sum_{n: r_n \in (x_0,x)} \frac{1}{2^n} \leq \sum_{n: r_n \in (x_0,x_0+\delta)} \frac{1}{2^n} \leq \varepsilon \sum_{n=0}^\infty \frac{1}{2^n} = 2\varepsilon $$
this established the right-continuity.

Proving $f$ is continuous at an irrational $x_0$ is similar. Given $\varepsilon > 0$, choose $\delta$ so small such that all $\{r_n\}$ in the interval $(x_0-\delta,x_0+\delta)$ satisfies $2^{-n} < \varepsilon$, we can do this because $x_0$ is irrational. Then proceed as above.
Comment: Could you explain why the second inequality holds?
Comment: @Andrew  Let $N$ be the smallest number of the set $\{n | r_n \in (x_0, x_0 + \delta ) \}$, then $$\sum_{n : r_n \in (x_0, x_0 +\delta ) } \frac{1}{2^n}  \leq \sum_{n\geq N} \frac{1}{2^n} = \frac{2}{2^N} < 2\varepsilon$$ the last step follows from our choice of $\delta$.


Android Studio thinks interface is class after rename

Question: In my Java project in Android Studio (Hedgehog 2023.1.1), I had this interface declared:
public interface Fetcher {
    ...
}

I later renamed it to Manifest using Refactor.  Everything worked fine afterward.  My app built and ran successfully.  However, Android Studio is highlighting places where I implement the interface saying, "Interface expected here":
public class SomeImplementation implements Manifest {
    ...
}

When I hover over Manifest, the IDE identifies it as public final class com.example.MyApp.Manifest.  When I click on Go To -> Type Declaration, nothing pops up.
I've tried cleaning the build and restarting the IDE but the issue persists.  Like I said, my app builds and runs just fine.  How can I get Android Studio to realize that it really is an interface?
Comment: I already had this issue once, restarting the IDE by "invalidate cache and restart" did solve the issue. However, on the question of why this happened I have no idea.
Comment: Weird.  When I do that, it works briefly upon restart.  That is, it shows `Manifest` as an interface.  However, after a few seconds, it goes back to showing it as a class.
Answer: It looks like Android Studio got confused because the class Manifest already exists as android.Manifest.
Renaming the interface to something like MyManifest fixed the issue.


How do you change Highlighted WPF DataGridCell populated from DataSet?

Question: I managed to change the color of the highlighted column in the code behind. If the row is selected, it is necessary that the cell be in a different color. It would be nice if it could be done in a designer.
It should be a different color when selected
The following is an example:
  Dim s As Style = New Style(GetType(DataGridCell))
  s.Setters.Add(New Setter(BackgroundProperty, Brushes.LightBlue))
  s.Setters.Add(New Setter(BorderThicknessProperty, New Thickness(0)))
  s.Setters.Add(New Setter(ForegroundProperty, Brushes.Black))
  s.Setters.Add(New Setter(TextBlock.TextAlignmentProperty, TextAlignment.Right))
  DgwRacunStavke.Columns(DgwRacunStavke.IndexKoloneNaOsnovUNaziva("Može da se upiše u refundaciju")).CellStyle = s

I tried this in a designer but binding doesn't work because I probably made a mistake:
   <DataGrid.CellStyle>

     <Setter Property="Background" Value="{StaticResource bojaZaIsticanjeKoloneUGridu}"/>
     <Setter Property="BorderBrush" Value="{StaticResource bojaZaIsticanjeKoloneUGridu}"/>
     <Setter Property="Foreground" Value="{StaticResource bojaFontaZaIsticanjeKoloneUGridu}"/>
    </Style>
   </DataGrid.CellStyle>

Obviously I need a trigger for IsSelected ...
EDIT: Solution
XAML:

    </Style>

CODE BEHIND:
 DGW.Columns(DGW.IndexKoloneNaOsnovUNaziva("Može da se upiše u refundaciju")).CellStyle = FindResource("DataGridCell_Isticanje")

Answer: Have you tried to put the <Setter> before the </Style.Trigger> It should look something like this.


Replacing column values with loop result pandas

Question: I have dataframe that looks like this:
State   State_theft_sum Model_1 Model_year_1
Alabama 2154    Chevrolet Pickup (Full Size)    2005.0
Alaska  547 Chevrolet Pickup (Full Size)    2003.0
Arizona 5270    Honda Accord    1997.0

DF goes on and on, so changing values separately isn't the way. I though i might be able to replace them using result of loop which would format string as I want it to be, here is the loop:
for model_year in df_total['Model_year_1']:
    model_year = model_year.split('.')
    model_year = model_year[0]
    print(model_year)

Result of the loop:
2005
2003
1997
2004
1996
1997
(...)

I need this to be formatted as a string as I will use it as text for Choropleth chart.
Is there any way I can change the values inside a column of DF without needing to create new DF from the loop and then joining them and after that deleting the column with .0?
Answer: You could probably just convert it to a float, then to an int and then to a str to avoid the loop.
df["Model_year_1"] = df["Model_year_1"].astype('float').astype('int').astype('str')

Comment: I tried doing that but then i have this error: "ValueError: invalid literal for int() with base 10: '2005.0'"
Comment: I didn't realize the years were strings. I've updated the answer.


Regression with zero inflated continuous response variable using gradient boosting trees and random forest

Question: I have a data set with a lot of 0 values for the continuous response variable (about 50%). I want to understand how well gradient boosting/random forest deals with this problem. My colleague suggested doing a two part model with classification as the first step to predict the 0's and second step doing regression. Is this necessary?
p.s. I'm using xgboost in R.
Comment: Maybe not necessary, but sounds like a good idea. It would be easy enough to compare the out-of-sample performance between the two approaches for whatever loss function you chose ...
Answer: Updated problem statement
Given data:

comprised of 50% zero padding, 50% of something else
sufficient in size and complexity that xgboost (or equivalent) is needed
nonzero data is described by a multivariate linear relationship so multivariate regression is apropos

Show:

HOW to split task into "is zero vs. is not" and "if not, then fit linear"
WHEN to ...

Solution
Here is our data.

We can use the Kaggle "Human Resource Analytics" challenge
dataset, but with modified goal.
In the challenge, the goal is to predict "whether" the employee will
leave, so the output is the class, not the regression.  We have to
modify that for our purposes.  Let's suppose that the "satisfaction"
is some HR self-congratulatory hack, and poorly represents actual
satisfaction.  Let's presume also that a strongly truly satisfied
employee doesn't tend to leave, and one that is unsatisfied does tend
to leave.

Process:

first we use gbm (xgboost or other) to use all columns but satisfaction level and "left" to determine if they left.
second we use the left class to regress on satisfaction.
finally we compare to see if there are two fundamentally different sets of "physics" driving satisfaction.

Execution

I am going to use r + 'h2o', but the process and results should generalize to any gradient boosted machine including xgboost.  I like the H2O flow interface through the browser.  I also like to use a random-forest as a robust estimator of central tendency.  It is really hard to over-fit a random forest.

Fit of nominal (did employee leave)
#library
library(h2o) #gbm

#spin up h2o
h2o.init(nthreads = -1) #use this computer to the max

#import data
mydata <- h2o.importFile("HR_comma_sep.csv")

mydata[,7] <- as.factor(mydata[,7])

#split data
splits <- h2o.splitFrame(mydata,
               c(0.8))

train.hex <- h2o.assign(splits[[1]], "train.hex")
valid.hex <- h2o.assign(splits[[2]], "valid.hex")

#stage for gbm
idxx <- 1:10
idxx <- idxx[-c(1,7)]

idxy <- 7

Nn   <- 300
Lambda <- 0.1

#fit data
my_fit.gbm <- h2o.gbm(y=idxy,
                      x=idxx,
                      training_frame = train.hex,
                      validation_frame = valid.hex,
                      model_id = "my_fit.gbm",
                      ntrees=Nn,
                      learn_rate = Lambda,
                      score_each_iteration = TRUE)

h2o.confusionMatrix(my_fit.gbm)

The purpose of training/validation is to "dial in the parameters" to a decent level, and to estimate operational uncertainty.  When the dials are set, and we have estimates of how what step 1 errors are, then we train on the whole data to move to the second step.  In this case I am moving fast so that is not done here.  I predict on the model used for tuning parameters.
Convergence is fair, although the example here is nothing close to rigorous.

Here is the baseline RF
my_fit.rf <- h2o.randomForest(y=idxy,
                              x=idxx,
                              training_frame = train.hex,
                              validation_frame = valid.hex,
                              model_id = "my_fit.rf",
                              ntrees=150,
                              score_each_iteration = TRUE)

h2o.confusionMatrix(my_fit.rf)

Its confusion matrix is:
Confusion Matrix (vertical: actual; across: predicted)  for max f1 @ threshold = 0.469005852414851:
          0    1    Error        Rate
0      9008  100 0.010979   =100/9108
1        98 2762 0.034266    =98/2860
Totals 9106 2862 0.016544  =198/11968

Comparison of this with confusion matrix from the GBM fit suggests we have around 93.6% positive predictive value, and we are in the right area to not be over-fitting.
Here is the confusion matrix for the GBM:
Confusion Matrix (vertical: actual; across: predicted)  for max f1 @ threshold = 0.410323012296247:
          0    1    Error        Rate
0      9030   87 0.009543    =87/9117
1       103 2723 0.036447   =103/2826
Totals 9133 2810 0.015909  =190/11943

So let's predict the "did they leave" on the whole data, and use it to model the "satisfaction_level".
Here we predict and augment the data
pred_left.hex  <- h2o.predict(my_fit.gbm,
                         newdata = mydata,
                         destination_frame="pred_left.hex")

mydata2 <- h2o.cbind(mydata, pred_left.hex)

Here we make prediction of "satisfaction"
#stage for second gbm
idxx2 <- 1:13
idxx2 <- idxx2[-c(1,7)]

idxy2 <- 1

Nn   <- 300
Lambda <- 0.05

#split data
splits2 <- h2o.splitFrame(mydata2,
                         c(0.8))

train2.hex <- h2o.assign(splits2[[1]], "train2.hex")
valid2.hex <- h2o.assign(splits2[[2]], "valid2.hex")

#fit data
my_fit2.gbm <- h2o.gbm(y=idxy2,
                      x=idxx2,
                      training_frame = train2.hex,
                      validation_frame = valid2.hex,
                      model_id = "my_fit2.gbm",
                      ntrees=Nn,
                      learn_rate = Lambda,
                      score_each_iteration = TRUE)

As long as it is a "fair" model, the variable importance is going to show whether this has utility.
Here is the "RF as a gross reality check"
my_fit2.rf <- h2o.randomForest(y=idxy2,
                              x=idxx2,
                              training_frame = train2.hex,
                              validation_frame = valid2.hex,
                              model_id = "my_fit2.rf",
                              ntrees=150,
                              score_each_iteration = TRUE)

The RF converged

Fit metrics give mae around 0.13

Here is the GBM results

Now, I did nearly nothing in the way of real tuning.  A decent GBM can usually outperform an RF for accuracy by quite a bit.  It can also over-fit, which is a bad thing that requires a litle time and effort to resolve.
Our typical error scale of 13% (mae = mean absolute error) isn't bad.  It is consistent with the RF, but there is something much more interesting.
Here is what the GBM gives for variable importance (and the key you are looking for).

Notice that the "P0", the probability of staying, is the number 2 most informative value in the set.  It is stunningly more important than salary, work hours, accidents, or previous review.  It is, in fact, more informative than the bottom 8 variables combined even though it is a function of them.
From this we might say that any HR that claims all "satisfaction scores" are created equal, given this data, is junk; we shouldn't be as surprised as they are that the "best and most experienced employees are leaving prematurely".  With only a little work, the predictive values should be moved to the late 90's, even on real-world data.
This also shows how having the class probabilities as an input can be substantially informative.
Thoughts:

If P0 was contrived as log of probability, or as log-odds, then it might be even more informative for the fundamental learner, the CART.
Again, the GBM could be substantially improved by adjusting control parameters.  This is practically "shoot from the hip".

UPDATE:
There is also a package called "lime" that is about unpacking variable importance from black box models like random forests. (ref)
Answer: You might want to try ZeroInflatedRegressor which is a pre-built implementation by Robert Kübler:
from sklego.meta import ZeroInflatedRegressor
import xgboost as xg
xgboost_with_zeros = ZeroInflatedRegressor(
    classifier=xg.XGBClassifier(),
    regressor=xg.XGBRegressor()
)

Do cross validate this - boosting models can overfit, and now you're using two. The dataset of the regressor is naturally much smaller than the dataset of the classifier, so the best hyperparameters may be very different.


Tape capacity and backup routine in Linux

Question: I have a HP Ultrium 5-scsi tape device on a Linux server and I'm currently using a HP LTO-5 Ultrium RW (model C7975A) tape and I have a couple of questions regarding this setup and does it work.
1 - It seems this tape can reach 3TB for storage considering compression. I'm not using any compression to backup a specific folder. Without compression, how much data this tape can hold? I couldn't find this information anywhere.
2 - I'm trying to do a backup from a folder that has 329GB and it's asking to insert a second tape to continue the backup process. Is this normal? The command I'm using to start this backup is tar cvMf /dev/nst0 var/Data/backup
3 - I'm using Ubuntu 20.04 on the server.
Can anyone share a light on this? I don't have much knowledge on this.
Answer:
LTO 5 has 1.5TB physical capacity without any compression.

Not normal, and looks like there is already some data on
tape. It is possible to check free space on tape -
Determine remaining capacity of LTO tape
Comment: I believe that solved this problem. The process finished without any errors. Thank you very much for your help! I would upvote your answer but I don't have enough rep to do it.
Comment: try: tar cvf /dev/nst0 var/Data/backup
Comment: "M" in tar is for multi-volume, maybe it is a reason.
Comment: Thank you for your help @batistuta09. To mitigate any chances of a tape with some data in it, I opened a brand new tape and tried the same thing. It's keeping asking for a second tape. For testing purposes I inserted a third tape and now it's asking for a fourth tape. I really don't know what's going on here.
Comment: I double checked the amount of data I'm sending to tape and it's ~329GB total.


How to add some text in all pages of an application

Question: This question is asked by someone in an interview.
I have one application which have 50000 Asp.net web forms, 10000 html pages and 20000 asp pages.
I want to add something in all pages after body tag how can i achive this
Comment: write a C# program that take all webfiles(authorized) in a directory. use regex to find the required position of document and add tags in it
Comment: Is it useful when something is not in header/body and just after it? Well if it is, then read files through C# or VB.NET and use XML libraries to find relevant positions and add some text in it.
Comment: There is an ASP.NET / IIS pipeline with several options to 'filter' the response stream. The inclusion of HTML and ASP is an indication they want you to find (name) the lowest level handler.
Answer: You could do the trick by a Custom HttpModule
Module c#
using System;
using System.Web;
public class HelloWorldModule : IHttpModule
{
    public HelloWorldModule()
    {
    }

    public String ModuleName
    {
        get { return "HelloWorldModule"; }
    }

    // In the Init function, register for HttpApplication
    // events by adding your handlers.
    public void Init(HttpApplication application)
    {
        application.BeginRequest +=
            (new EventHandler(this.Application_BeginRequest));
        application.EndRequest +=
            (new EventHandler(this.Application_EndRequest));
    }

    private void Application_BeginRequest(Object source,
         EventArgs e)
    {
    // Create HttpApplication and HttpContext objects to access
    // request and response properties.
        HttpApplication application = (HttpApplication)source;
        HttpContext context = application.Context;
        string filePath = context.Request.FilePath;
        string fileExtension =
            VirtualPathUtility.GetExtension(filePath);
        if (fileExtension.Equals(".aspx") || fileExtension.Equals(".html") || fileExtension.Equals(".asp"))
        {
            context.Response.Write("
" +
                "HelloWorldModule: Beginning of Request" +
                "

");
        }
    }

    private void Application_EndRequest(Object source, EventArgs e)
    {
        HttpApplication application = (HttpApplication)source;
        HttpContext context = application.Context;
        string filePath = context.Request.FilePath;
        string fileExtension =
            VirtualPathUtility.GetExtension(filePath);
        if (fileExtension.Equals(".aspx")|| fileExtension.Equals(".html")|| fileExtension.Equals(".asp"))
        {
            context.Response.Write("

" +
                "HelloWorldModule: End of Request
");
        }
    }

    public void Dispose() { }
}

Web.config
<configuration>
  <system.webServer>
    <modules>
      <add name="HelloWorldModule" type="HelloWorldModule"/>
    </modules>
  </system.webServer>
</configuration>

EDIT
As commented by @Andreas there are two distint pipeline to precess asp classic and aspx, so the HTTP module can't do the trick with .asp pages, probably only with an ad hoc ISAPI filter can work every request, but generally there is not used for writing an header to all web pages
Comment: Afair this won't work for Classic-ASP pages as .Net and Classic-ASP use different pipelines (aspnet_isapi.dll versus asp.dll). An ISAPI Filter would be a solution.
Answer: You can try Ctrl+H
and to restore Ctrl+Z
Comment: yep this can do the trick, but I would not answer in this way in a technical interview for sure
Comment: Yes but I wanted to advice this, because the owner of the question is using Classic-Asp. So this method can achive that. I'm also using this kind of replace operations, in my own usage...


Policyd-rate-limit for Postfix correctly configured but still wont work

Question: I have tested policyd-rate-limit on my developer server and there is everything work correctly.
But my production server wont work with policyd-rate-limit.
My configuration:
Postfix
( dev ) version: 3.4.13
( prod ) version: 3.1.15
main.cf:
<code>    smtpd_recipient_restrictions = check_policy_service { unix:ratelimit/policy, default_action=DUNNO }
....
</code>
In logs /var/log/syslog I dont see any entry like this example: 001/001 hit since 60s or insert id firstname.lastname@example.com
So daemon policyd-rate-limit cant defer the message.
Of course I dont see any errors in logs. Database has been tested mysqlite and mysql and yaml configure package for Python3. Unfortunately stil no solution :(
Answer: OK problem has been solved.
Policyd-rate-limit installed from default debian repository ( Debian 9.13 ) cant correctly to work with Postfix 3.1.15.
So I have uninstalled package policyd-rate-limit along with configuration files.
After I installed manually policyd-rate-limit using pip3. Of course it needs to be copied manually config file and init scripts/services files to correct location. After standard configuration it works. I noticed also that option "limits_by_id" dont work in this case :(


Contradiction in two ways to derive Fourier transformation of error function

Question: In the question, Fourier transformation of error function is derived as follows:
$$
\int_{-\infty}^\infty \operatorname{erf}(x)e^{-ixk}dx=\frac{2}{ik} \exp \left(\frac{-k^{2}}{4}\right).
$$
However, in the paper, following equation holds for any $a,b\in\mathbb{C}$:
$$
    \int \operatorname{erf}(a z) e^{b z} d z=\frac{1}{b} e^{b z} \operatorname{erf}(a z)-\frac{1}{b} \exp \left(\frac{b^{2}}{4 a^{2}}\right) \operatorname{erf}\left(a z-\frac{b}{2 a}\right).
$$
According this formula, Fourier transformation of error function is not well-defined because
$$
\int_{-\infty}^\infty \operatorname{erf}(x)e^{-ixk}dx=-\frac{1}{ik} e^{-ik \infty}-\frac{1}{ik} e^{ik \infty}+\frac{2}{ik} \exp \left(\frac{-k^{2}}{4}\right).
$$
Which part of the above discussion is wrong?
Comment: The Fourier transform of $\operatorname{erf}x$ is not defined in the usual sense since the defining integral diverges. But it is well-defined in the [distributional](https://en.wikipedia.org/wiki/Distribution_(mathematics)#Tempered_distributions_and_Fourier_transform) sense.
Answer: The first equation gives a correct formula for the Fourier transform of the error function. As metamorphy writes, the integral on the left hand side is not defined, but the Fourier transform in a distributional sense is defined and equals
$$
\frac{2}{i} \exp\left(-\frac{k^2}{4}\right) \operatorname{pv}\frac{1}{k}
$$
where $\operatorname{pv}\frac{1}{k}$ is the principal value distribution.
The second equation gives a primitive function of the error function, but since the integral over all the reals is not defined, this formula cannot be used to determine the Fourier transform.


Unable to extract zip file through Java code made in nodeJs code

Question: What I want to do, is to create a zip file in nodeJs and later extract it through Java code(An already written Java program to work on the zip).
I am able to create zip file in nodeJs using jszip but my java code is unable to extract that zip file(Though my finder can extract it, even my extract code in nodeJs also works).
nodeJs code to create zip:
this.zip = function (sourceDirectory, zipFile, excludParent) {
        var zip = new JSZip();

        var list = getFiles(sourceDirectory, excludParent);
        for (var i = 0; i < list.length; i++) {
            var obj = list[i];
            if(typeof(obj.source) == "undefined"){
                if (excludParent)
                    zip.folder(obj.target.substring(obj.target.indexOf("/") + 1));
                else
                    zip.folder(obj.target);
            }else {
                if (excludParent)
                    zip.file(obj.target.substring(obj.target.indexOf("/") + 1), fs.readFileSync(obj.target), {base64: true});
                else
                    zip.file(obj.target, fs.readFileSync(obj.target), {base64: true});
            }
        }
        zip.generateNodeStream({type:'nodebuffer', streamFiles:true, compressionOptions:'DEFAULT'})
            .pipe(fs.createWriteStream(zipFile))
            .on('finish', function () {
                console.log(zipFile + " written.");
            })
    };

    var getFiles = function (sourceDirectory, excludeParent) {
        var list = [];
        if (excludeParent) {
            if (fs.lstatSync(sourceDirectory).isDirectory()) {
                var fileList = fs.readdirSync(sourceDirectory);
                for (var i = 0; i < fileList.length; i++) {
                    list = list.concat(getFiles_(sourceDirectory + sep, fileList[i]));
                }
            }
        } else {
            list = getFiles_("", sourceDirectory);
        }
        return list;
    };

    var getFiles_ = function (parentDir, path) {
        var list = [];

        if (path.indexOf(".") == 0) return list;
        if (fs.lstatSync(parentDir + path).isDirectory()) {
            list.push({target: parentDir + path});

            var fileList = fs.readdirSync(parentDir + path);
            for (var i = 0; i < fileList.length; i++) {
                list = list.concat(getFiles_(parentDir + path + sep, fileList[i]));
            }
        } else {
            list.push({source: parentDir + path, target: parentDir + path});
        }
        return list;
    };

Java code to extract file:
public void unzip(String zipFilePath, String destDirectory) throws IOException {
        File destDir = new File(destDirectory);
        if (!destDir.exists()) {
            destDir.mkdir();
        }
        ZipInputStream zipIn = new ZipInputStream(new FileInputStream(zipFilePath));
        ZipEntry entry = zipIn.getNextEntry();
        // iterates over entries in the zip file
        while (entry != null) {
            String filePath = destDirectory + File.separator + entry.getName();
            if (!entry.isDirectory()) {
                // if the entry is a file, extracts it
                extractFile(zipIn, filePath);
            } else {
                // if the entry is a directory, make the directory
                File dir = new File(filePath);
                dir.mkdirs();
            }
            zipIn.closeEntry();
            entry = zipIn.getNextEntry();
        }
        zipIn.close();
    }

This code throws following stacktrace:
java.util.zip.ZipException: only DEFLATED entries can have EXT descriptor
    at java.util.zip.ZipInputStream.readLOC(ZipInputStream.java:310)
    at java.util.zip.ZipInputStream.getNextEntry(ZipInputStream.java:122)
    at module.builder.ZipUtility.unzip(ZipUtility.java:57)
    at module.builder.DataPatcher.unZipAndroidImageFiles(DataPatcher.java:624)
    at module.builder.DataPatcher.patchAndroid(DataPatcher.java:145)
    at module.builder.FXMLDocumentController$5.call(FXMLDocumentController.java:324)
    at module.builder.FXMLDocumentController$5.call(FXMLDocumentController.java:312)
    at javafx.concurrent.Task$TaskCallable.call(Task.java:1423)
    at java.util.concurrent.FutureTask.run(FutureTask.java:266)
    at java.lang.Thread.run(Thread.java:745)

This java code works fine if i create a zip file through an application (i.e winzip, winrar, zip made by finder etc.) but it throws ava.util.zip.ZipException: only DEFLATED entries can have EXT descriptor while extracting zip made through above mentioned nodeJs method.
Comment: You could try using [Apache Commons Compress](https://commons.apache.org/proper/commons-compress/zip.html) or at least read the documentation on the linked page which should explain some things. One is that data descriptors only work reliably when using deflated entries and I'd guess jszip always writes them. Maybe you can change the `compressionOptions` you're passing in your nodejs code to only use deflated entries.
Comment: This is known problem of Java: https://bugs.openjdk.java.net/browse/JDK-8143613
Answer: I ran into the same problem today.
The issue is with the streamFiles:true passed as an option to zip.generateNodeStream(). From the docs:

When this options is true, we stream the file and use data descriptors at > the end of the entry. This option uses less memory but some program might > not support data descriptors (and won't accept the generated zip file).

Removing the streamFiles:true option should work as long as you are not worried about memory usage.


Choice of t-test for the following problem

Question: Nine students are selected at random and obtained scores on their verbal and quantitative reasoning tests. We are supposed to test the belief that the students possess the two abilities in different degrees.
This is just a summary of the question. I would like to know if these the two sets of scores are independent or not. Because by my logic, since these tests test different abilities of each student, the scores for each test would be independent of each other. But I'm not so sure.
Comment: Welcome to CV. Since you're new here, you may want to take our [tour], which has information for new users. Please type your question as text, do not just post a photograph (see [here](https://stats.meta.stackexchange.com/questions/3175/top-k-list-of-reasons-to-close-a-question-immediately/3176#3176))
Comment: Also please add `[self-study]` tag and read its [wiki](http://stats.stackexchange.com/tags/self-study/info). Then tell us what you understand thus far, what you've tried & where you're stuck. We'll provide hints to help you get unstuck. Please make these changes as just posting your homework & hoping someone will do it for you is grounds for closing.
Comment: Oh alright. So sorry about that.  I'll correct it.
Answer: Since for each student, you have a pair of results (quantitative and verbal test scores),  paired t-test, should be used.
Comment: But quantitative and verbal reasoning tests test different abilities right? So shouldn't they be independent?
Comment: No they shouldn't. Independece refers here to a way you obtained your samples. Sample from quantitative abilities and sample for verbal abilities are obtained from the same group. And you can match each qualitative abilities result with "its own" verbal ablilities result. So they are not independent in above meaning
Comment: Lukasz: Certainly it is technically possible that they are independent! It is unlikely, but it would be hard to justify the claim that any two things measured on the same person must be statistically dependent! (PS I agree with your answer regarding the "Choice of t-test" title of the question, see my answer.)
Comment: I shouldn't have been using word "independent" here. "paired" is better.
Answer: The first answer (paired t-tests should be used) is correct if the question is what test should be used to compare the means, however that isn't quite what the thread question asks if I understand it correctly.
Independence is a rather strong assumption, it says "they don't have anything to do with each other". If they come from the same student, they are connected, even though in a certain respect they may be quite different. Technically they may be indeed (approximately) independent, but that's a strong claim to be investigated in its own right, rather than something to be assumed when picking a test for testing something else, namely whether they are on average the same. So you'd play it safer not assuming independence, even though there may not be strong dependence between them. I haven't tried to form an opinion based on the data (edit: an earlier version of the question had showed data but this seems to have been edited out in the meantime) whether there is such dependence indeed; you could compute a correlation and test the hypothesis correlation=0, but apart from the fact that correlation=0 isn't equivalent to independence but only one aspect of it, also your test would have a small power detecting dependence because of the small sample size.
A different issue is whether a t-test testing equality of averages, paired or unpaired, is precisely the right thing addressing the question that is asked on the scanned document or whether that is even possible from these data; equality of averages and "students focusing on both abilities to the same degree" (which was the wording on the original scanned document that has now apparently been edited out) isn't really the same thing. (What I write here still applies to the version of the question currently visible to me, if only in sense, not literally... the beauty of responding to questions that are substantially edited while responding...)
Comment: With reference to that last paragraph, the question I received from my teacher was in the context of paired t-tests.
Comment: If you only want to get the question of your teacher right in the sense of your teacher, the straight "paired" answer tells you everything. However if you are curious why this is so, and about the general nature of independence (which isn't a stupid thing to be wondering about at all), you can dig a bit deeper...
Comment: Thank you for that detailed explanation of the "independence" issue. I'm new to this but I get it now.


Meaning of a notation

Question: What is the meaning of the notation . I cannot search for such questions on google.
Comment: It can be used to denote a map from $I$ to $\mathbb{R}$, map and function are used interchangeably in many cases. Usually we call $\mathbb{R}$ the co-domain and $I$ the domain, the word "image" is reserved for the elements in the co-domain that are mapped to by the function given over the domain.i.e $f[I] \subset \mathbb{R}$ but not always $f[I] = \mathbb{R}$
Comment: search by image ?
Answer: It means that $f$ is a function from the set $I$ to the reals $\mathbb{R}$. Usually by $I$, one denotes an interval of $\mathbb{R}$.
Answer: $f \colon I \to \mathbb R$ means that $f$ is a function with domain $I$ and range $\mathbb R$. So, for every $i \in I$ there is a unique $x \in \mathbb R$ (where $\mathbb R$ is the set of all real numbers) such that $(i,x) \in f$ (we also write $f(i) = x$ for this).

Meaning of a notation


Coin flip gamble

Question: You have an amount of money to bet on a fair coin flipping and landing on heads. How much should you bet as a function of your balance to maximize your probability of profiting if you play $x$ times?
Comment: Try this http://en.wikipedia.org/wiki/St._Petersburg_paradox
Comment: @sas That is a fascinating and useful case, but he is talking about a much simpler, non compounding gambling situation, you may just be complicating things more than necessary.
Answer: Seems like the previous answers didn't fully appreciate the question, which I think has multiple interpretations.
Let $A$ be your initial amount of money, and $x$ be the number of times you need to bet. Now there are two ambiguities:

Do you have to bet exactly $x$ times (i.e., you cannot bet all of your money until the final bet)?
Do you have to bet the same amount each time?

Suppose (1) and (2) are both true. If $x$ is odd you have exactly a 50% chance of profiting, no matter what. However, if $x$ is even you have strictly less than a 50% chance of profiting. For example, if $x = 2$, then you have only a 25% chance of profiting.
Suppose (1) is false and (2) is true. Then clearly, you will simply bet some odd number of times $t \leq x$, and have a 50% chance of profiting.
Suppose (2) is false (regardless of (1)). Then you can actually achieve a $1 - .5^x$ chance of profiting. For each round $i$ until you win a coin toss, simply bet $A * .5^{x-i+1}$ dollars. $\sum_{i=1}^\infty A*.5^i = A$, so clearly
you will never go broke, because $x$ is finite. However, each bet is more than the sum of all previous bets. Thus, once you win one coin toss, you will have more than $A$ dollars, and can simply bet a small enough sliver of your profits for the remaining bets to guarantee that you profit.
Answer: If it is a truly fair coin, with a 50% chance of each side coming up, the chance of winning and the chances of losing are equal, and losing $X$ dollars or gaining $X$ dollars cancel out to an average profit of $0$ dollars absolutely regardless of how much you bet.
Comment: If you bet half your balance and win then lose, you won't be back where you started.
Comment: no, im saying that each individual bet has an average payout of zero. If i bet 1 dollar, then i have 50% chance of winning 1 dollar and 50% chance of losing 1 dollar. Adding these together we get $0.5*1+0.5*-1=0$ So for that bet, the average value is zero.
Comment: But we're not betting a set amount of money, we're betting a set fraction of what we have at each coin toss. The expected value is still whatever we started with, though.
Comment: ok, then replace 1 in the previous equation with x, x being the amount you are betting. No matter how much you bet, the expected value of each bet is zero, there is no profitable way to bet. How you bet doesnt change the mean of the result, but it does affect the standard deviation of the result
Comment: for more read http://en.wikipedia.org/wiki/Gambler%27s_ruin

Coin flip gamble


Calculating an aggregated score

Question: I'm out of my element when dealing with statistics, so I hope you'll be able to offer me some guidance.
I'm working on a project where students will apply for scholarships, and then a panel of people (reviewers) will independently evaluate each application and score a number of questions from values 1 through 5.
Given this, a theoretical data set might look like:

Student
Reviewer
Score 1
Score 2
Score 3
Score 4

Anna
Mr. Jones
5
4
5
5

Anna
Ms. Smith
4
4
4
5

Anna
Mr. Quinn
4
3
5
4

Anna
Mr. Blair
5
5
4
3

Anna
Ms. Brown
4
4
3
4

Billy
Mr. Jones
5
4
4
4

Billy
Ms. Smith
3
4
3
3

Billy
Ms. Brown
4
4
2
4

I would like to create a single value per student that fairly represents all the other scores in the data set, giving consideration to the number of reviews completed for the student. (Note that in this data set, "Anna" was reviewed five times, while "Billy" was reviewed only three times).
What mathematical process should I use to create such a value??? I've considered the obvious average of all scores, but does the fact that Anna had more reviews than Billy change the statistical relevance of that simple calculation? Is there something more that should be done to account for the variation in number of reviews?
Desired Outcome:

Student
Overall / Aggregate Score

Anna
???

Billy
???
Answer: An average seems a sensible way of comparing the scores. The only thing to take into account is that if a student has got fewer reviews, then the average score of that student will be more sensitive to the presence of a very strict or a very generous reviewer, while students with a higher number of reviewers will have a more fair average score. Coming back to your questions:
"does the fact that Anna had more reviews than Billy change the statistical relevance of that simple calculation?"
The higher the number of reviewers, the more statistically relevant the score is. The lower the number, the more subject to chance it is. Specifically, if the standard deviation of the reviewer's scores is $ \sigma_r $, then the variability $\sigma_s$ of the student's average score is $ \sigma_s \approx \sigma_r / \sqrt{N}$, where $N$ is the number of reviewers. You want $\sigma_s$ small, so you can reduce $\sigma_r$ (that is, having very good reviewers) or increase $N$ (a higher number of reviewers, even if they have less quality as e.g. if they have lower expertise).
"Is there something more that should be done to account for the variation in number of reviews?"
You could set a minimum number of reviewers to reduce the chances of a student getting values that are not representative, a consequence of some extreme or biased reviews. Also, you could at the end check if there are students that performed exceedingly well or bad, but they happen to be among those with the lowest amount of reviews. For those cases, maybe further reviewing is advisable as a sanity check, to ensure that their average score is actually representative of the student's performance.

Calculating an aggregated score


How to create a solfege instrument in Logic Pro X?

Question: I'd like to create a midi instrument with a human voice of fixed-do solfege in Logic Pro X, for example, whenever I hit a C on the midi controller, I'd like it to make a "do" sound. How can I do this?
Comment: Did you ever create or find such an instrument? If so could you share?
Answer: You have at least two options:

Find a VST/AU instrument that includes those sounds. There are plenty of vocal synths but I don't personally know of any that do "fixed-do" as opposed just "oohs" and "aahs". I wouldn't be surprised if one exists though.
Create your own with EXS24. So, in other words you'd record yourself or somebody else singing through the range of solfege syllables that you'd like to use. Then you'd create a custom EXS24 (Logic's sampler) instrument using those audio file(s). [tutorial] [vids]


Python reading proccess memory with ctypes

Question: I am attempting to read my players health.  I have been on a roll but have run into a problem. I am able to read what type of information is at a certain address but can't read what the actual value is, for example here is the response I receive.
<ctypes.c_char_Array_64 object at 0x0000000002EBF9C8>

I am looking for what information is held in the c_char_Array_64 object but have no idea how I would go about it.
Here is my code:
class User:
    ctypes.wintypes.DWORD = "Entity"
    ctypes.wintypes.c_int = "Team"
    ctypes.wintypes.c_int = "Health"
    ctypes.wintypes.c_int = "Player"

    def getSelfInfo(self):
        adr1 = clientdll + dw_LocalPlayer
        adr2 = ctypes.create_string_buffer(64)
        bytes_read = ctypes.c_size_t()

        (rPM(PROCESS.handle, adr1, adr2, sys.getsizeof(ctypes.wintypes.DWORD), ctypes.byref(bytes_read)))
        print adr2
t = User()
t.getSelfInfo()

Comment: Side-note: `sys.getsizeof(ctypes.wintypes.DWORD)` is not getting you a useful value; it's telling you the Python interpreter's (rough) overhead to store the Python level class. If you want the size of a C `DWORD`, you want `ctypes.sizeof(ctypes.wintypes.DWORD)`. You also can't do `ctypes.wintypes.DWORD = "Entity"` and the like, that's not how you declare a variable (you're actually overwriting the `DWORD` type). I assume your goal it to make a `ctypes` struct; look at [the docs for how you're supposed to do this.](https://docs.python.org/3/library/ctypes.html#structures-and-unions)
Answer: You need to get the value:
print(ar2.value)

From the docs:

If you need mutable memory blocks, ctypes has a create_string_buffer()
function which creates these in various ways. The current memory block
contents can be accessed (or changed) with the raw property; if you
want to access it as NUL terminated string, use the value property:
>>> from ctypes import *
>>> p = create_string_buffer(3)      # create a 3 byte buffer, initialized to NUL bytes
>>> print sizeof(p), repr(p.raw)
3 '\x00\x00\x00'
>>> p = create_string_buffer("Hello")      # create a buffer containing a NUL terminated string
>>> print sizeof(p), repr(p.raw)
6 'Hello\x00'
>>> print repr(p.value)
'Hello'
>>> p = create_string_buffer("Hello", 10)  # create a 10 byte buffer
>>> print sizeof(p), repr(p.raw)
10 'Hello\x00\x00\x00\x00\x00'
>>> p.value = "Hi"
>>> print sizeof(p), repr(p.raw)
10 'Hi\x00lo\x00\x00\x00\x00\x00'
>>>

Answer: The empty slice of most ctypes array types will return the Python equivalent type.  So to convert your 64 byte buffer to a str (in Py3 bytes), you can do:
print ar2[:]

That will read the full raw 64 bytes mind you. If you want to read it as a C-style string (so the first NUL byte terminates the Python equivalent str), you'd use .value:
print ar2.value

Comment: It fails to print any value just a blank line
Comment: @Scheming: If `ar2` is the empty string both of those may `print` nothing, because printing the `NUL` byte doesn't display anything on most terminal setups. I should have been a bit more clear. If you were writing to a file, or processing the data in Python, the difference is meaningful, but not necessarily printing to the terminal. If you assigned `a[12] = b'a'`, then printed, even with `NUL`s preceding the `a` you'd see the `a` printed, likely at an offset.
Comment: It is still unclear, I don't understand how this would allow me to get the health of my player
Comment: @Scheming: Well, assuming the `ReadProcessMemory` is actually reading the correct location, it's still reading far too much (see my comment on the question; you're trying to read a thousand bytes or so into that buffer by misusing `sys.getsizeof`, which is a buffer overflow). I don't know where in the process the health is, and if ASLR is involved, odds are the location of the DLL is not where you think it is. Your example is missing too much information.


NumericUpDown bloquear Down

Question: Como fazer para bloquear ou controlar o estado "Down" do componente NumericUpDown do Windows Forms ?
Ex: Primeiro momento o usuário faz um "cadastro", ele pode Adicionar ou Remover a Quantidade, na segunda possibilidade o usuário pode "editar" adicionar ou remover a quantidade adicionada, contanto que o Down não seja menor que a quantidade salva anteriormente no cadastro.
Comment: já deu uma olhada na [documentação](https://docs.microsoft.com/en-us/dotnet/api/system.windows.forms.numericupdown.minimum?view=netframework-4.7.2)?
Comment: @AlvaroAlves Sim, mas a principio não encontrei uma solução ou não entendi ao certo a documentação. Por isso a pergunta aqui no StackOverflow.
Comment: Edite sua pergunta e adicione o que você já tentou fazer
Comment: @samuelrvg O que você quer dizer com controlar? Você quer mudar o "step" dele? Por exemplo: diminuir de 5 em 5, ao invés de 1 em 1
Comment: Se entendi bem ele quer que só exista a opção para aumentar - embora isso não tenha feito sentido para mim, pois se o usuário incrementar sem querer, não conseguirá diminuir.
Comment: @AndersonCarlosWoss Eu pensei que fosse isso também, mas aí caí na mesma ideia. Não faz sentido ter apenas uma opção.
Comment: @LINQ o que quero é em determinado momento "Cadastro" ele pode alterar o valor normal, tanto o Up quanto o Down, em outro momento por exemplo "Editar" quero que seja apenas o UP, bloqueando assim o Down, faz sentido agora ?
Comment: eu recomendo você criar um textbox e dois botões e fazer isso customizado.. de acordo com sua lógica.. pq não tem nada nativo pra bloquear apenas o down,a não ser que você vá no change event e se o valor for de decremento do valor atual você bloqueia e não deixa ( e.Cancel )
Comment: Você definir o valor minimo para a quantidade atual, não resolve?
Comment: https://docs.microsoft.com/en-us/dotnet/api/system.windows.forms.numericupdown.minimum?view=netframework-4.7.2
Answer: Penso que é isto que quer.
<code>numericUpDown.ReadOnly = true;
</code>
Answer: Acho que nesse sua situação o melhor seria o numericupdown puxar os dados salvos e jogar na opção minimum do seu numeric assim o minimo sempre vai ser o que o usuario salvou por ultimo

NumericUpDown bloquear Down