How would you interpret this p-value in relation to page traffic due to page features?

Question: I'm exploring some manual approaches to understand whether specific changes on a site can be deemed conclusive and statistically significant.
I appreciate that any A/B testing platform has a reporting part of doing this job; however, changes have been implemented without any platform, so my best bet was pulling out data and doing this exercise manually.
The scenario
36 pages, 24 of which have a feature the remaining 12 have not.
Looking at the daily traffic values, traffic rose by +50% on the group where the feature is in.
But I need to provide a confidence interval or a statistically significant coefficient for the senior management.
The two groups of data (8760 & 4380 entries respectively) are heteroscedastic (Levene test suggests it) and not normally distributed (after all they are traffic data).

Note: I believe the data are not normally distributed as the bell curve is not properly centered, but I might be wrong in saying so. Still have to gain experience in this field.
The result
When running a Welch's test as below, I get a p-value that is absnormal:
stats.ttest_ind(faq['traffic'], no_faq['traffic'], equal_var=False, axis=0)
Ttest_indResult(statistic=-23.253270956567135, pvalue=1.3551062210749643e-114)
Now, if the H0 is that the page feature does not influence the traffic, the high p-value here confirms me the opposite.
Question
What I'm struggling to understand is the very high p-value that goes beyond the 100% mark.
Am I doing something wrong? Should I use a different test?
What to calculate a confidence score?
Comment: *"What I'm struggling to understand is the very high p-value that goes beyond the 100% mark"*. But the p-value is close to zero !!!
Comment: If your data is non-normal, you may wish to reconsider the use of an independent Welch's test. See this [Q/A](https://stats.stackexchange.com/questions/530812/t-test-states-difference-of-donation-is-significant-when-z-test-claims-not-what/530818#530818).
Answer: You're saying the p-value is really high, but it is the opposite. Your p-value is really small, but you may be overlooking the scientific notation.
$P=$1.3551062210749643e-114$ = \frac{1.3551062210749643}{10^{114}} \approx \frac{1}{10^{114}} << 0.05 = \alpha$
Comment: $P<\alpha$ means you will reject the null hypothesis.
Comment: I am possibly doing so, have still few concept of statistic that I need to grasp well. So given is so small... the null hypothesis is confirmed, so there is no evidence the new features have had any effect?

How else can I explain/explore this?
Comment: Actually, you're right, I was too focused in reading the other way round. So, correct me whether I'm wrong, I basically have 100% of statistical significance. Should I add anything else for the sake of communication? BTW appreciated the other link
Comment: @AndreaMoro Non-normality of the data notwithstanding, the interpretation of your Welch test is that the two groups are significantly different under an 95% confidence.
Comment: @AndreaMoro For communication, I suggest you include visualizations that show what your statistics are indicating. It might seem redundant, but it can really clarifying what the stats are saying to your target audience.
Comment: (+1) visualizations are so often overlooked !
Comment: Definitely I need to do something, and I totally stand what you guys said. Without visual it will difficult to let people understand. Though the nature of data doesn't suggest me anything better than a cumulative traffic aggregated by day. Anything else you can think of?
Comment: @AndreaMoro One suggestion that relates to the hypothesis test itself is to (1) pair the counts by date, (2) calculate the date-wise difference in the counts, then (3) plot a histogram of those differences. If one group was clearly greater than the other, then you should not see the distribution overlap with zero.
Answer: You are testing whether 2 independent samples have the same expected values.

"What I'm struggling to understand is the very high p-value that goes beyond the 100% mark".

The p-value is low, not high. As for interpretation: If these two samples actually have the same expected value, then the probability of observing these data, or data even more extreme, is very low.
It would be a good idea to check if these data are approximately normally distributed.
Comment: How can I check for normal distribution if the data are split by page and date? I don't think this is possible. I can group by date, but the overall result is still a time series. The only way I can think is to group by the value I'm testing and add a count every time a given item is found?
Comment: @AndreaMoro You should be able to check whether `faq['traffic']` and `no_faq['traffic']` are normally distributed.
Comment: I'm not sure why page and date have anything to do with the distribution ? Perhaps you can post a plot of the histograms of both samples. ie if using `matplotlib` then `hist()` or `histogram()` in `numpy`.
Comment: All I mean is that - by nature - those values are unlikely to be normally distributed because I have an uplift. But thinking to it more rationally, this might not always be the case. So I did update the post above to include a couple of chart just for completeness.
Comment: Does this answer your question ? If so please consider marking it as the accepted answer. If not, please let us know why. Also, if you haven't already, please consider upvoting it.


Amazon Linux server - change time to British Summer Time?

Question: My Amazon Linux server at EC2 is showing GMT times, instead of BST ones this morning. How do I change the server time so that it is running off BST instead?
Comment: All servers should use UTC.  For this very reason.
Answer: And here it is.
sudo vi /etc/sysconfig/clock

Edit the zone to "Europe/London" or your own local timezone
sudo tzdata-update

...and then probably restart the webserver etc to properly fix everything.
Answer: Run the command:
dpkg-reconfigure tzdata
and choose Europe/London
Comment: I think this is a Debian-based command, whereas Amazon Linux is RedHat-based.
Comment: [ec2-user~]$ dpkg-reconfigure tzdata
-bash: dpkg-reconfigure: command not found


Nginx 405 not using specified error_page (static contents)

Question: I've got a webserver that is designed to return 503 for all content except the favicon requests. This is a failover server that is set as a lower priority on load balancers. In the event that backend application servers are all offline, requests will overflow onto this web server, serving a 503 and some static content apologising for the service outage.
Its working fine for GET requests. However, its returning 405 default responses when a PUT/POST request is sent to the server.
Here is a snippet of my configuration:
# FILE: nginx.conf
daemon off;
pid /hab/svc/sorry-web/var/pid;
worker_processes auto;

events {
  worker_connections 512;
}
http {
  rewrite_log on;

  # Temporary files
  client_body_temp_path /hab/svc/sorry-web/var/client-body;
  fastcgi_temp_path /hab/svc/sorry-web/var/fastcgi;
  proxy_temp_path /hab/svc/sorry-web/var/proxy;
  scgi_temp_path /hab/svc/sorry-web/var/scgi_temp_path;
  uwsgi_temp_path /hab/svc/sorry-web/var/uwsgi;

  # Mime Types
  include /hab/svc/sorry-web/config/mime.types;

  server_tokens off;
  more_clear_headers Server;
  server_names_hash_bucket_size 256;

  variables_hash_max_size 8192;
  variables_hash_bucket_size 512;

  # GZip
  gzip on;
  gzip_http_version 1.1;
  gzip_comp_level 2;
  gzip_types text/plain text/css application/x-javascript text/xml application/xml application/xml+rss text/javascript;

  # Default server
  include /hab/svc/sorry-web/config/default_server;
}

# FILE: default_server.conf
server {
  listen 7003 default_server;
  server_name _;
  error_page 405 502 503 504 =503 @content;
  root /hab/pkgs/sorry/sorry-web/0.3.0/20200803032212/htdocs/default/busy;
  location @content {
    try_files $uri /index.html =404;
  }
  location / {
    try_files __force_503__.html =503;
  }
  include /hab/svc/sorry-web/config/favicon.conf;
}

And the response from a POST request:
# curl -vvv -XPOST http://localhost:7003/something
*   Trying 127.0.0.1:7003...
* TCP_NODELAY set
* Connected to localhost (127.0.0.1) port 7003 (#0)
> POST /something HTTP/1.1
> Host: localhost:7003
> User-Agent: curl/7.68.0
> Accept: */*
>
* Mark bundle as not supporting multiuse
< HTTP/1.1 405 Not Allowed
< Date: Mon, 03 Aug 2020 03:22:41 GMT
< Content-Type: text/html
< Content-Length: 154
< Connection: keep-alive
<

<title>405 Not Allowed</title>

405 Not Allowed

openresty

* Connection #0 to host localhost left intact

Answer: This happens because you specified a named location in error_page. In this case the request method is not changed, but passed on to that location in an internal redirect. So it is effectively trying to POST to a static file. Thus you get a 405 because nginx could not POST to a static file to get the desired error_page. (This is really meant for use when the error page will be dynamically generated by some web application.)
If you simply want to serve a static content to all such requests, point to the desired document directly in error_page rather than a named location.
Comment: Thanks for the response Michael! I tried changing the `error_page` lines to the following, with no change in behaviour in the response:

`error_page 405 =503 /index.html;`
Comment: @Predominant I expect you probably need to get rid of both `location` blocks too, and possibly replace them with a reasonable one.
Comment: Do you have an example of what constitutes a reasonable one? Thanks again for the response :)


Rendering blocks inside node

Question: I am building a Drupal 8 site. The site will have basic pages (nodes) that have three fields: a title, a body and a list of embedded blocks.
The idea is to allow the editors to create content blocks by using the new functionality of Block Types in Drupal 8. Those blocks can be referenced and arrangaed inside the page by using an entity reference field.
I have built the necessary infrastructure and I can reference my custom blocks from the page and render them in the template. The trouble comes when I want to set a custom template for my blocks, for example I would like to have a custom template: block--image-gallery-block.html.twig that would be used when rendering blocks of type Image Gallery Block.
With Twig debug mode enabled I can see that Drupal is looking for a template for the entity reference field, and then starts to render the referenced block fields instead of the block itself, so I can not use any template for it (not even the default block.html.twig).
I've thought about using a custom template for my field and render here the block the way I like. Unfortunately my field can reference blocks of multiple types, so this solution won't work for me.
How can I make Drupal pick the proper template for the referenced blocks?
Edit: solution
I am explaining here the solution I've ended with after reading @ssibal and @4k4 answers.

I've built some new content-types that will represent the blocks.
I've modified my Basic Page content type to have an entity reference field that points to the blocks. This field simply references other nodes from the content types that I want (the ones I've made in the step 1).
In the display options of my basic page, I choose which view mode I want to use for rendering the blocks.
I use the view mode that I've set up in the step 3 to build custom templates for my block content types.
Since I do not want block content types to be accessed directly with a URL, I've implemented a hook_node_access to throw a 404 error when directly loading a node of my block content types.
Answer:
Those blocks can be referenced and arrangaed inside the page by using
  an entity reference field.

These "block contents" should be a different content type, since you are not using (based on your writing) the block functionality at all. After that, you can define your own display for this content type, and also create a twig template for it.
Comment: I've gone with this solution. I have created multiple content types that represent blocks (as many as block types I need) and modified my *Basic page* entity reference field to point to those block content types.

For extra safety I've disabled the `/node/XXXX` paths for those nodes of a block type (I do not want them to be viewed directly) using a `hook_node_access`.

Thank you very much!
Comment: Wise solution for using hook_node_access on that!
Answer: Block content is not the same as Block.
Block content is a content entity
Block is a config entity.
Normally you place "block content" in a "block" to put it on your drupal site. Then you get a block template around your block content.
You are using "block content" as entity in a reference field, then this is no "block" and will not involve the block theme.
But you should be able to do the same theming in the field template of the reference field.
You can go inside the items loop and check every item, which kind of block content is inside and make your adjustments.
Comment: Thank you very much for your answer. I didn't know that block content entities did not use the block theme, it is much clearer for me now.
Comment: Thank you so much! This block vs block content explanation was enlightening.
Answer: You can use Block Token to expose blocks as tokens, then use Token Filter to use these tokens on the node pages, so they can render the blocks. See: How to use tokens in a node?

Rendering blocks inside node


What Happens if you Instantiate an Object Whose Class Has No Constructor?

Question: I just realize I've been doing that and it seems like the objects' properties are still being set when I use
object->set($property, $value);

What is the expected behavior in this situation?
Comment: What exactly is the situation here? Constructor are optional and are used to perform operations that you want when any object are instantiated. If your class has no constructor it would simply not be called. Any other method would work..
Comment: I see. This seems really obvious now. I had used a constructor for every other class but this one and I was surprised it worked. Escpecially because I called it with "$obj_var = new myClass($name)" and I thought a fatal error would be caused by calling it the $name variable if I have no constructor to handle it.
Answer: object->set($property, $value);

set is just an method of the object's object here, probably you are referring to setter method. which takes two arguments and pass it to the class property. the behavior of setting the class depends on the code of set method, there are some benefits of using this method.
there are two ways for storing the data in a class, one way is to directly assign the values to class property for example
class Foo {
    public $a;
    public $b;
}

if you need to assign the values to the class property you would do like.
$object = new Foo();
$object->a = 'hello';
$object->b = 'world';

now the class property $a will contain the value hello and the class property $b will contain the value world, however there is a problem to this approach, we can never tell the user what type of data should come in. if we need to store only integers in $a there is no way we can do that. to overcome this you can use a setter meth, wherein we declare the class property as protected or private, and set the value through a class method.
class Foo {
    protected $a;
    protected $b;

   public function set($a) {
       //you can validate the data here before assigning.
       $this->a = $a;
   }
}

you can simply google about getter and setter method and get more information.
Class Constructor

class constructor is nothing but an method which is invoked automatically when you instantiate an object. consider that you want to instantiate an object by forcing the user to provide the user id first. or may be you want to do some useful calculation before other methods are called. this is where class constructor comes into picture. consider the below example
class Bar {

    protected $userId;

    public function __construct($userId) {
        $this->userId = $userId;
        //any more code execution that needs to be done while instantiating the class can be placed here
    }
}

so when you instantiate the object
$object = new Bar();

this will result into error. since you haven't provided the userId. so the correct way is.
$object = new Bar(1);

now the class property $userId will hold the value one upon the instantiation of the object.
hope this helps you.
Comment: I see. I was thinking that you had to have a constructor but I guess you don't. That makes sense. But, on a different subject, how can your public function set($a) have only one argument? You need to know which property to set and what value to set it to.
Comment: key, values combination are needed in array, and that example is probably using array. for example in your class property you can declare `protected $_data = array()` and you assign it through setter method like this `public function set($key, $value) { $this->{$key} = $value }` it depends on what you want to do. and also remember a class with code `class A { }` is a valid class, notice that it does not have any property or constructor or any method defined.
Comment: here is an excellent tutorial by nettuts which explains object oriented php for beginners http://net.tutsplus.com/tutorials/php/object-oriented-php-for-beginners/
Comment: I might mark your answer accepted, but I still want to know why you have set($a). I guess it is an example of a class with only one externally-settable property? By the way, if you want a slightly more complex OOP question, see my new one: http://stackoverflow.com/questions/10511859/how-to-handle-inheritance-of-a-function-with-many-parameters
Comment: yes, that is just an example, in my later comment i have explained about using two arguments for set method. you can set as many argument as you want, one, two, three or more. just declare the number of argument in your function and decide what to do with it, i used one argument in the example because i am using the class property as a variable not as an array. since we have already declared class property then only thing we need is it's value. so one argument. if you want both the class property and the value to be set then you need to do that with array. as explained above


How do I find the element by class name for a button on Chrome?

Question: I want to try make a script that auto-clicks a button, but I can't find what to put in the class name. How do I find it?
window.onload=function(){
    setInterval(autoClick,100);
  }
  function autoClick(){
    if(document.getElementsByClassName("???").length>0){
    document.getElementsByClassName("???")[0].click();
  }
}

I don't know how to get the element by class name.
Comment: Does your button has a class assigned? Post you HTML.
Answer: If you're trying to click with coordinates use document.elementFromPoint(x, y).click();
https://codepen.io/niko8888/pen/aryoMb?editors=0010
If you are using Chrome, open up the inspector, inspect the element you want to click.  Right click over the element in the Elements panel and then scroll down to Copy > Copy JS Path and then paste the result.  It should be a querySelector for that specific element.
Comment: There is no element name. How do click with coordinates instead?
Comment: @DavidtheGoat123 if you want to click with coordinates look above, I edited my answer.  Click on the codepen,


Rails Memcached Usage

Question: I'm looking into using memcached for my rails application.  I was considering using it on my member search, but I am confused because there are multiple parameters for the search which will be changing through user selection.
This is an example of a query for the search:
 @results = Painter.city(params[:city].downcase).state(params[:state]).tools(tools).transportation(trans).travel_distance(params[:travel_distance]).insurance(insurance).employee(emp).subcontractor(sub).available(true).paginate(:page => params[:page], :per_page => 20).where("premium = ? AND banned = ?", false, false).order('last_name')

This seems like a likely candidate for memcached, but I am unsure.
Please provide direction.
Answer: You could certainly cache this using Memcached. You must start by deciding on a format for your cache keys, and when you have several different criteria/fields that uniquely determine a cache record (such as in your case) you can probably just concatenate them in a pre-determined order, using some kind of string to separate them. For instance, your cache key may look like this:
@results = Rails.cache.fetch([params[:city].downcase,
                   params[:state],
                   tools,
                   trans,
                   params[:travel_distance],
                   insurance,
                   emp,
                   sub,
                   params[:page]
                  ].join('/')) do
  Painter.city(params[:city].downcase)...  # rest of your query
end

You may want to tweak or clean up the format, but the gist of it is that you must be able to calculate a consistent cache key as a String. The easiest way to do that for multiple fields is to join them using a separator (I chose /, but you can use other separators if you choose.)
Note also that I left out the :per_page => 20, since that is hard-coded within your controller code and will not vary based on user input. If you decide to allow users to customize how many records are returned, you would need to include that in the cache key as well. Same goes for the where("premium = ? AND banned = ?", false, false) clause, and available(true).
You can use Rails caching for any kind of content that is non-trivial to look up from its original source (i.e., if it involves DB queries).
Of course a very important consideration to keep in mind is cache expiration: if/when you add new records to your DB that match the criteria of data you have in your cache, you must be sure to expire the data in your cache manually, or else set an automatic expiration when you write to the cache so that it will eventually be purged and refreshed on its own.
Using Memcached in Rails, manual expiration of the cache involves a delete:
Rails.cache.delete(key)

Or to use automatic expiration, use the :expires_in option:
Rails.cache.write(key, value, :expires_in => 1.minute)

Comment: Alright cool, wont the query still execute each time then? Seems I would run the query then store the results?
Comment: This makes sense thank you. If you have a minute can your provide some examples of when to cache and when not to?  For example, my user's have profiles.  Would caching a user's profile using a fragment be another likely candidate?  It's all about increasing performance right?
Comment: Also, in the above code how would I add the result of the query to the cache based on the key?
Comment: I've updated my answer to include some more details, including cache expiration which is very important
Comment: My example snippet above sets the cache value to your `@results` instance variable, meaning the cache will hold the value of the array of results
Comment: Also don't miss the [Rails Guide to Caching](http://guides.rubyonrails.org/caching_with_rails.html) if you haven't seen it
Comment: Oh duh, I forgot to use `fetch(key) do ... end` instead of `write` :) `fetch` skips running the "expensive" code in the block if it finds the key first (I'm getting tired :) Updated my answer.
Comment: let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/28233/discussion-between-brian-and-stuart-m)

Rails Memcached Usage


Let $u$ be transcendental over $\mathbb{Z}_p$. Why is $t^p-u$ irreducible over $\mathbb{Z}_p(u)$?

Question: The following is an extract from my book

I'm having trouble understanding the very last part of the proof, namely, why can't the terms of highest degree cancel?
Answer: The top degree term of $v(u)$ has degree divisble by $p$. The top degree term of $uw(u)^p$ has degree congruent to $1$ mod $p$ (the $w(u)^p$'s leading term has degree divisible by $p$ and multiplying by $u$ adds $1$) and in particular not divisible by $p$. So these two terms are unequal and hence cannot cancel.


Is a 'Type 1 error' an indication of error, a probability of error, a measure of error or all of the above?

Question: I have come across two definitions of 'Type 1 error' in dictionaries published by Oxford University Press:

In hypothesis testing, the incorrect rejection of the null hypothesis when it is true. Alternatively termed false-positive.
A Dictionary of Business Research Methods (2016)
The probability of being wrong in rejecting a null hypothesis about a parameter in a model.
A Dictionary of Social Research Methods (2016)

I am not a statistician, but these seem to me to be two different definitions. After further reading, I'm led to believe that there are two different approaches to hypothesis testing:

A 'classical' method of conducting hypothesis testing which produces one of two results: either True or False.
A Bayesian factor approach which produces a probability as its result, rather than returning either True or False.

I suppose I have two related questions:

Am I correct in thinking that the two different approaches to hypothesis testing I note above exist?
If so, is the Type 1 error as probability a measure of how erroneous the error is, or how probable it is that there is an error in the first place?

The reason I ask my second question is that in my language we use a different word for an error (='mistake') and error (='measure of error', or literally 'astrayness'). In other words, senses 1.1 and 1.2 here use different words in my language, and if the probability-based Type 1 error is a measure of error, we would have to use a different term for it than that used for the true/false Type 1 error.
Thanks for taking the time to read. Any help will be gratefully received!
Answer: You are extremely perceptive in the way you've asked the question.  To begin with, the second definition is completely wrong.  For it to be in a dictionary of social research methods is quite astounding.  First of all, a type I error is a result or an action, not a probability (the dictionary should have said "type I error probability or type I error rate (but see below)" if they wanted to address a risk.  But a more fundamental problem with definition 2. is that null hypothesis statistical tests (NHST) assume the null hypothesis is true.  The probability of being wrong about rejecting the null hypothesis is the prob. the null is true when you reject.  Frequentists can't know that but have already assumed the null is true.  You are also very perceptive in using words like "measure of error" or "astrayness".  Below I try to use slightly better wording.
"Errors" in NHST are not really errors in the traditional sense.  The p-value is "the degree to which the data are embarrassed by the null hypothesis" and is a measure of "surprise" given by the data if H0 is true.  Type I error probability is the probability of making an assertion of a nonzero effect if the effect is truly zero.  Once you understand the difference between assertions and conclusions, things get more clear.  These issues have been written about by William Briggs, Steve Goodman, and many others, and I am putting together training materials that goes into details and gives a lot of references.  I go into detail about some of the concepts in some of my blog articles here.
William Briggs has decoded Ronald Fisher's statement "either an event of low probability has been observed or the null hypothesis is false" to be logically equivalence to "an event of low probability has been observed".  So p-values tell us less than we need.  Cohen has shown that proof by contradiction doesn't really work when uncertainties are involved; it only works with logical certainties.
The shortest definition of p-values and type I error probabilities I can come up with are as follows.  The p-value is the probability that someone else's data will be more impressive than yours if their data were generated with the null hypothesis in force.  If you set a rejection levels of $\alpha=0.05$ then type I error is the probability that the p-value will be less than 0.05.  This is by definition 0.05 if the p-value is computed exactly correctly, there was only one look at the data, and the sample size is a constant.  When multiplicities exist as when doing sequential testing, and if each test is done at a nominal $\alpha$ level, the type I error will be $> \alpha$.
If you use a hard-and-fast rule that you'll make an assertion of an effect if p < 0.05 (which is seen as quite silly nowadays) then type I error probability is the probability of making an assertion of an effect when there is no effect.  With the single test fixed sample size situation, this is 0.05 by definition, independent of data.  As Jeffrey Blume has pointed out, this results in all kinds of craziness, because most type I errors occur when the observed effects are small.  Not to condition on the observed data when computing probabilities really misses this point, and fixing type I error at, say, 0.05 no matter how large the sample size becomes will insure that your type I error never vanishes no matter what is going on.
Pure subjective Bayesian statistics could be said to not require complex notions of inference and counterfactuals and use only observed quantities in calculations.  Bayesian posterior probabilities allow you to carry along probabilities that assertions hold, to make optimum decisions.  Once you think probabilistically, notions of assertions, conclusions, inductive vs. deductive reasoning, etc. can be somewhat ignored.  Posterior probabilities are fully conditional on the data observed so far, and quantities such as P(unknown effect > 0 | data) will be low when the data are tilted away from a positive effect.  One minus this probability is the probability that the effect is zero or is in the wrong direction.  So Bayesian posterior probabilities have a dual purpose - providing both evidence for and evidence against unknown effects.  With NHST you can only amass evidence against H0, never evidence in favor of H0.
Comment: Thank you very much for taking the time to write such an in-depth reply, and for your kind words. It's taking me quite some time to process all the information that you've shared! I find it strange to think of a Type 1 error as a probability rather than an error in the traditional sense.

If I understand you correctly, the classical Type 1 error is "the assertion of a nonzero effect if the effect is truly zero", whilst in NHST Type 1 error is "the probability assertion of a nonzero effect if the effect is truly zero".

Or am I guilty of oversimplification?
Comment: Apologies, I had assumed that the website would notify me of your edits. As a friend of mine says: "Never assume!". I see now where you edited the text. Thanks again for your invaluable help.
Comment: Again you're thinking clearly.  I failed to distinguish a type I error and the probability (often incorrectly called a "rate") of a type I error.  I'll try to edit the post in a bit.
Comment: Just a quick prod as I'd love to be able to accept your answer!
Comment: I made those edits a few days ago
Answer: The classic one produces " Accept or Reject" the HO: ( Null hypothesis)
The type one error is committed when you Reject  the null hypothesis instead of Accepting it
Comment: I'm using definitions so no empirical data needed.
Comment: type I error is the rejection of a true null hypothesis
Comment: No, type I error is the probability of asserting a nonzero effect if the effect is in fact zero.  But this does not deal with the original question and doesn't provide the deep meaning of 'rejection of H0'.
Comment: Not sure what example is needed.
Comment: I need an empirical example to support the argument


Any good IIS Tracer?

Question: I'm trying to find an IIS Tracer to be able to look at all requests on my ASP.NET application.
I found the IISTracer tool which looks great. The problem is that my server is running with an AMD64 architecture which is not compatible with this software (the ISAPI filter fails when restarting IIS).
Do you guys know any other option? I'm running Windows 2k3 with IIS6.
Answer: Wireshark and Follow TCP stream?
Comment: That's a good option. But I'm looking for something that is on a higher level and that does not go too deep. The output from IISTracer is exactly what I'm looking for. The HTTP Method, Client IP, Length, URL, Response Time.
Answer: Do you need currently running requests, or just recent requests?  You may want to consider LogParser and running directly against your IIS Logs.  You can get impressive results in near real time.  It supports checkpoints too so it will only give results since the last time you ran it.  Various stats programs like SmarterStats are good for that too.
Comment: I'd like to have the running requests too, but I'd be ok without too. I've looked on these IIS6 logs and it appears that it doesn't output the response time, is it true?
Comment: Actually, I just found out that i can customize which information will be logged. I'll be trying this.
Comment: Yes, time-taken is the one you probably one.  Turn on referrer and the bytes fields too.  As for running requests IIS7 addresses it nicely, but for IIS6 you'll need a 3rd party tool.  I don't know of any free or inexpensive ones.  So, the running requests is difficult, but the on-going requests is definitely possible.
Answer: You might consider using a tool like Paros Proxy:
http://www.parosproxy.org/functions.shtml
It runs client side so it won't give you view of "all requests", but it could help you debug a session that you control.
Comment: I'm already using firebug to trace my own requests. But I'd like to log requests from everyone.

Any good IIS Tracer?


How can I prove ($number \ of\ verticies \over size \ of\ maximum\ independent \ set$ ) $\leq$ chromatic number?

Question: How can I prove
$$n/ \beta(G) \leq \chi(G)$$ .
I thought of using an algorithm that selects a maximum independent set and gives them a color and etc. but this does not necessarily give a minimum coloring.
Is this inequality even true?
Answer: Roughly speaking, an optimal coloring of the vertices cannot use more than $\chi(G)$ independent sets of size $\alpha(G)$ (the order of the largest independent set that you call $\beta(G)$). More formally, consider an optimal coloring, and let $S_k$ be the $\chi(G)$ independent sets of this coloring.
$$
V=\bigcup_{k=1}^{\chi(G)}S_k,
$$
Since, the independent sets are pairwise disjoint, and that $|S_k|\le \alpha(G)$ for all $k$:
$$
n=\sum_{k=1}^{\chi(G)}|S_k| \le \sum_{k=1}^{\chi(G)}\alpha(G) = \chi(G)\alpha(G)
$$
which yields
$$
\chi(G)\ge \frac{n}{\alpha(G)}.
$$
Answer: Assume $\frac{n}{\beta(G)}>\chi(G)$. We start by considering a $\chi(G)$-coloring of $G$. Its existence is guaranteed by the definition of chromatic number.
In particular, every monochromatic set, that is, sets of vertices that are assigned the same color, is an independent set, and has size no more than $\beta(G)$.
Consequently, $n=\sum_c(\text{# of vertices with color }c)\leq\beta(G)\chi(G)<n$, which is a contradiction.
Comment: the proof could be easily turned into a direct proof rather than a proof by contradiction .  i would be nice to see the direct proof .


How to subset rows based on specific values from all columns

Question: A sample dataset
v1 v2 v3 v4
1 CC DD EE
2 CC PP RR
3 EE QQ LL
4 OO RR EE
5 UU EE DD

I need to retain only rows that columns have DD and EE
v1 v2 v3 v4
1 CC DD EE
5 UU EE DD

Im trying with df %>% filter_all(any_vars(. %in% c('DD', 'EE', 'bla bla'))) but this is not considering the AND condition
   v1 v2 v3 v4
    1 CC DD EE
    5 UU EE DD

Comment: If you only have two strings to check, two rowSums will do: `d[rowSums(d == "DD") & rowSums(d == "EE"), ]`, where all non-zero & non-zero will be `TRUE`
Answer: Here is a base R option using rowSums
> df[rowSums(sapply(c("DD", "EE"), function(x) rowSums(df == x) > 0)) > 1, ]
  v1 v2 v3 v4
1  1 CC DD EE
5  5 UU EE DD

Data
> dput(df)
structure(list(v1 = 1:5, v2 = c("CC", "CC", "EE", "OO", "UU"),
    v3 = c("DD", "PP", "QQ", "RR", "EE"), v4 = c("EE", "RR",
    "LL", "EE", "DD")), class = "data.frame", row.names = c(NA,
-5L))

Comment: @thelatemail Thanks for correcting me. See my update
Comment: @AndresMora Since you have two criteria here, `>1` means both criteria are satisfied.
Comment: @AndresMora If you have `N` criteria, then change `>1` by `==N` for easy understanding.
Comment: actually im getting no results at all
Comment: what is the purpose of the "greater than 1" statement on `df[rowSums(sapply(c("DD", "EE"), function(x) rowSums(df == x) > 0)) > 1, ]`  ?
Comment: Can i have more than 2 criterias? Do i need to change the `>1` ?
Comment: thanks. just a quick note after messing around with this approach for a while: it doesnt like NA's
Answer: I guess this would work but it's not very concise:
library(tidyverse)
data <- tibble::tribble(~v1, ~v2, ~v3, ~v4,
                1, "CC", "DD", "EE",
                2, "CC", "PP", "RR",
                3, "EE", "QQ", "LL",
                4, "OO", "RR", "EE",
                5, "UU", "EE", "DD")
data %>%
  filter(v2 %in% c("DD", "EE") & v3 %in% c("DD", "EE") |
         v3 %in% c("DD", "EE") & v4 %in% c("DD", "EE") |
         v2 %in% c("DD", "EE") & v4 %in% c("DD", "EE"))

Answer: Using if_any
library(dplyr)
df %>%
   filter(if_any(v2:v4, ~  . == 'DD') & if_any(v2:v4, ~ . == 'EE'))
#  v1 v2 v3 v4
#1  1 CC DD EE
#2  5 UU EE DD

Or if there are many values, then use map/reduce
library(purrr)
df %>%
  filter(map(c("DD", "EE"), function(x) if_any(v2:v4, ~ . == x)) %>%
           reduce(`&`))
#   v1 v2 v3 v4
# 1  1 CC DD EE
#2  5 UU EE DD

Or paste the columns and then use str_detect
library(stringr)
df %>%
     filter(str_detect(str_c(v2, v3, v4, sep=""), "DD.*EE|EE.*DD"))
#  v1 v2 v3 v4
#1  1 CC DD EE
#2  5 UU EE DD

Comment: @AndresMora yes, but then you could use that in a range right?
Comment: @AndresMora You can also specify with select_helpers like `everything()` or `matches` etc
Comment: thanks but this will be limited to specific columns, right?
Comment: @AndresMora Not clear about your comment.  The columns are specified in a range `v2:v4` in second soluiton and in first
Comment: im thinking for the future. df might have multiple number of columns or different names


Limit and adherent points of the union of sets $H = ({\frac{1}{n}}) \times (\frac{n-1}{2n} , \frac{n+1}{2n})$ in $R^2$

Question: Firstly of all set $({\frac{1}{n}})$ a has limit point zero.
Then $(\frac{n-1}{2n} , \frac{n+1}{2n})$ for all $n$ at every $({\frac{1}{n}})$ has infinitely many limit points. But if $n$ approach infinity, then from both side it goes towards $1/2$.
So there is only one limit point: $ ({0}) \times (\frac{1}{2})?$
I am a bit confused how can I combine all this mess together.
Can you help me with it?
Comment: Is H subset R^3 or R^2?
Comment: @WilliamElliot in $R^2$
Comment: Explain in your title the use of ×.  (1/n) is not a set.  "Then .... " is  very confusing.  What is (0)×(1/2)?  Do you mean the point (0,1) in R^2?
Comment: @WilliamElliot I meant the point (0;1/2) in $R^2$
Comment: Are you asking what are the limit points of { ((2n-1)/n,  (2n+1)/n) in R^2 : n in N }?
Comment: @WilliamElliot No, I am asking what are limit points of the union of vertical intervals $({\frac{1}{n}}) \times (\frac{n-1}{2n} , \frac{n+1}{2n})$ in $R^2$
Comment: Your notation is incomprehensible.  Do you want the limit points of the union of { {n} × ((2n-1)/n, (2n+1)/n) : n  in N }?   Then you need to write it all out instead quick glib meaningless stuff that gets you ignored.
Answer: For each $n\in\Bbb N$ put $I_n=\{\frac 1n\}\times \left(\frac {n-1}{2n};\frac {n+1}{2n}\right)$. I assume that you are asking on the set $A'$ of limit points of a set $A=\bigcup I_n$. Since the set $A$ has no isolated points, $A'=\overline{A}$. It is easy to check that $x_0=(0,\frac 12)\in\overline{A}$ and each point $x\in\Bbb R^2$ different from $x_0$ has a neighborhood intersecting at most one of the segments $I_n$. So all  of the set $\overline{A}$ different from $x_0$ belong to a closure of a some set $I_n$. Thus $\overline{A}=\{x_0\}\cup\bigcup\overline{I_n}=\{(0,\frac 12)\}\cup\bigcup\{\frac 1n\}\times\left[\frac {n-1}{2n};\frac {n+1}{2n}\right]$.


Save data to custom field columns using entity_metadata_wrapper

Question: I have a simple custom module that creates a new field type.  The field has multiple columns in the database; the idea is that a user (or code) will enter a single value, and then that value is converted into several different formats and saved to the database columns.
Currently, this is working by using a method from the book Drupal 7 Module Development, where the user's original value is converted using a widget validate function.
It works great when a human is filling out a form; but the problem is, when I try to create an entity in code, using entity_metadata_wrapper, there's no widget, and thus, no widget validate function runs.
It looks like I need to look at hook_field_info and specify a property_type of 'struct' with a custom setter callback, but I can't find any documentation that describes how to use the property or getter/setter callbacks.
How can I use entity metadata wrappers with custom field database columns?
<code>/**
 * Implements hook_field_info().
 */
function device_id_field_info() {
  return array(
    'device_id' => array(
      'label' => t('Device ID'),
      'description' => t('Converts the input device ID and saves it to the
        database in various formats.'),
      'default_widget' => 'device_id_simple',
      'default_formatter' => 'device_id_raw',
      'default_token_formatter' => 'device_id_combined',
      'property_type' => 'device_id',
      'property_callback' => array('_device_id_property_callback'),
      ),
  );
}

/**
 * Callback to alter the property info of device id fields.
 *
 * @see device_id_field_info().
 */
function _device_id_property_callback(&$info, $entity_type, $field, $instance, $field_type) {
  $name = $field['field_name'];
  $property = &$info[$entity_type]['bundles'][$instance['bundle']]['properties'][$name];

  $property['type'] = ($field['cardinality'] != 1) ? 'list<deviceid>' : 'deviceid';
  $property['getter callback'] = 'entity_metadata_field_verbatim_get';
  $property['setter callback'] = 'entity_metadata_field_verbatim_set';
  $property['property info'] = device_id_property_info();

  unset($property['query callback']);
}

/**
 * Defines info for the properties of the device ID field data structure.
 */
function device_id_property_info($name = NULL) {
  // Build an array of basic property information for the device ID field.
  $properties = array(
    'raw_id' => array(
      'label' => t('Raw input ID'),
    ),
    'esn_hex' => array(
      'label' => t('Converted ESN in hexadecimal format'),
    ),
    'esn_dec' => array(
      'label' => t('Converted ESN in decimal format'),
    ),
    'meid_hex' => array(
      'label' => t('Converted MEID in hexadecimal format'),
    ),
    'meid_dec' => array(
      'label' => t('Converted MEID in decimal format'),
    ),
    'imei_hex' => array(
      'label' => t('Converted IMEI in hexadecimal format'),
    ),
    'imei_dec' => array(
      'label' => t('Converted IMEI in decimal format'),
    ),
    'iccid_hex' => array(
      'label' => t('Converted ICCID in hexadecimal format'),
    ),
    'iccid_dec' => array(
      'label' => t('Converted ICCID in decimal format'),
    ),
  );
}

/**
 * Implements hook_field_is_empty().
 *
 * Pseudo-hook.
 */
function device_id_field_is_empty($item, $field) {
  if ($field['type'] == 'device_id') {
    if (
      empty($item['raw_id']) &&
      empty($item['cap_dec']) &&
      empty($item['cap_hex']) &&
      empty($item['meid_dec']) &&
      empty($item['meid_hex']) &&
      empty($item['imei_dec']) &&
      empty($item['imei_hex']) &&
      empty($item['iccid_dec']) &&
      empty($item['iccid_hex'])) {
      return TRUE;
    }
  }
  return FALSE;
}

/**
 * Implements hook_field_widget_info().
 */
function device_id_field_widget_info() {
  return array(
    'device_id_simple' => array(
      'label' => t('Device ID text field'),
      'description' => t(
        'Allow the user to enter the device ID, and display it in
        whatever format it was entered'),
      'field types' => array('device_id'),
      'behaviors' => array(
        'multiple values' => FIELD_BEHAVIOR_DEFAULT,
        'default value' => FIELD_BEHAVIOR_DEFAULT,
        ),
      ),
    );
}

/**
 * Implements hook_field_widget_form().
 *
 * Pseudo hook
 **/
function device_id_field_widget_form(
  &$form, &$form_state, $field, $instance, $langcode, $items, $delta, $element) {

  switch ($instance['widget']['type'] == 'device_id_simple') {

    case 'device_id_simple':
      $element += array(
        '#element_validate' => array('_device_id_wrapper_validate'),
        'device_id_wrapper' => array(
          'input_id' => array(
            '#title' => t('Device ID'),
            '#type' => 'textfield',
            '#default_value' => isset($items[$delta]['raw_id']) ?
              $items[$delta]['raw_id'] : '',
          ),
        )
      );
    break;
  }
  return $element;
}

function _device_id_wrapper_validate($element, &$form_state) {
  //This function is also called when submitting the field
  //configuration form.  If so, skip validation since it
  //won't work anyway
  if ($form_state['complete form']['#form_id'] == 'field_ui_field_edit_form') {
    return;
  }

  $values = $form_state['values'];
  $language = $element['#language'];
  $field_name = $element['#field_name'];
  $item = $values[$field_name][$language][$element['#delta']]['device_id_wrapper'];

  foreach ($values[$field_name][$language] as $delta => $item) {
    if (is_array($item)) {
      if (array_key_exists('device_id_wrapper', $item)) {
        $conversion = new deviceIDConversion($item['device_id_wrapper']['input_id']);
        $conversion_values = $conversion->calculate();
        if ($conversion_values) {
          $new_values = array(
            'esn_hex' => isset($conversion_values['ESN_HEX']) ? $conversion_values['ESN_HEX'] : NULL,
            'esn_dec' => isset($conversion_values['ESN_DEC']) ? $conversion_values['ESN_DEC'] : NULL,
            'meid_hex' => isset($conversion_values['MEID_HEX']) ? $conversion_values['MEID_HEX'] : NULL,
            'meid_dec' => isset($conversion_values['MEID_DEC']) ? $conversion_values['MEID_DEC'] : NULL,
            'imei_hex' => isset($conversion_values['IMEI_HEX']) ? $conversion_values['IMEI_HEX'] : NULL,
            'imei_dec' => isset($conversion_values['IMEI_DEC']) ? $conversion_values['IMEI_DEC'] : NULL,
            'iccid_hex' => isset($conversion_values['ICCID_HEX']) ? $conversion_values['ICCID_HEX'] : NULL,
            'iccid_dec' => isset($conversion_values['ICCID_DEC']) ? $conversion_values['ICCID_DEC'] : NULL,
            'raw_id' => $item['device_id_wrapper']['input_id'],
            );
          form_set_value($element, $new_values, $form_state);
        } else {
          form_set_error($field_name, t('Your device ID doesn\'t match a valid format.  Check
            the device ID, verify it\'s correct, and type/scan it again.'));
        }
      }
    }
  }
}

/**
 * Implements hook_field_validate().
 *
 * Pseudo-hook.
 */
function device_id_field_validate($entity_type, $entity, $field, $instance, $langcode, $items, &$errors) {
  foreach ($items as $delta => $item) {
    if (!empty($item['raw_id'])) {
      $conversion = new deviceIDConversion($item['raw_id']);
      $conversion_values = $conversion->calculate();
      if (!$conversion_values) {
        $errors[$field['field_name']][$langcode][$delta][] = array(
          'error' => 'device_id_invalid_format',
          'message' => t('Your device ID doesn\'t match a valid format.  Check
            the device ID, verify it\'s correct, and type/scan it again.'),
        );
      }
    }
  }
}
</code>
Here is some example code I'm using in a test page to work with this content; when I do entity_load(), I can view the contents of the custom field, including the database columns I defined in hook_info().  When I wrap this in entity_metadata_wrapper() and try setting the field value, nothing happens.  Also, after wrapping, I can no longer see the field values, even with getPropertyInfo().
<code>$ent = entity_load('node', array('2955'));
$new_ent = entity_metadata_wrapper('node', $ent['2955']);
$new_ent->field_device_id->meid_hex = 'a1000002747883';
$new_ent->save();
dsm($new_ent->getPropertyInfo());
</code>
Comment: Just to confirm - are the changes you made to `hook_field_info()` working from a 'get' perspective? Are you able to access (for example) `$node_wrapper->field_device_id[0]->esn_hex->value()` if you load an existing entity and inspect it?
Comment: You might want to look at [`EntityMetadataWrapper::validate()`](http://drupalcontrib.org/api/drupal/contributions%21entity%21includes%21entity.wrapper.inc/function/EntityMetadataWrapper%3A%3Avalidate/7), which hooks into a `validation callback` that you can presumably define on your field type/individual properties. Docs are sketchy though, you're right.
Comment: Yes, working in a php test page, when I just do entity_load('some id') and then dsm() the result, I can see all the field columns and their values.  However, when I pass the loaded entity to entity_metadata_wrapper, it says that the data type in invalid, which doesn't make sense, because the data is the entity I just loaded with entity_load().  I'll add the code I'm using to the original post; maybe I'm using it incorrectly.
Comment: Ok, my problem was that entity_load() returned an array; fixed.  But when I wrap that entity, try setting the field value, and then do getPropertyInfo(), all I see is a bunch of metadata about the field, and I can no longer access the field values themselves, even though they were accessible before being wrapped.
Answer: To access a field value from the wrapper try:
$new_ent->field_device_id->meid_hex->value();
or for the whole entity:
$entity_object = $new_ent->value();
Answer: You can try the following:

$node = node_load($nid);
$wrapper = entity_metadata_wrapper('node', $node);
//- Set Lang
$wrapper->language->set('en');
//- Set Title
$wrapper->title->set('test');
//- Set Body Value
$wrapper->body->set(array('value' => 'Some text', 'format' => 'full_html'));
//- Set Custom field
$wrapper->your_custom_field_name->set('field value');
$wrapper->save();


Why does NSCalendar have two init methods with similar parameter types that accepts one of the calendar identifier constants?

Question: Why does NSCalendar have two init methods with similar parameter types that both accept one of the calendar identifier constants?  What is the point of having two init methods that do the exact same thing?  Does anyone know the reasoning behind why Apple would add this information to the documentation this way or why the class is even created this way?
Here is the first init method:
init?(calendarIdentifier ident: String)

Here is the second init method:
init?(identifier calendarIdentifierConstant: String)

Link to Apple's NSCalendar Class Reference
Comment: @LeoDabus Is there a reason why a developer would want to use the string version instead of the enum version which never fails?
Answer: That seems to be a bug in the Swift 2 import of the Objective-C interface.
In Objective-C there are – at it is usual with Foundation classes –
both a instance method
- (id)initWithCalendarIdentifier:(NSString *)string
// Initializes a newly-allocated NSCalendar object for the calendar specified by a given identifier.

and a class (factory method):
+ (NSCalendar *)calendarWithIdentifier:(NSString *)calendarIdentifierConstant
// Creates and returns a new NSCalendar object specified by a given identifier.

and the following two statements are (almost) equivalent:
NSCalendar *cal = [[NSCalendar alloc] initWithIdentifier:@"..."];
NSCalendar *cal = [NSCalendar calendarWithIdentifier:@"..."];

In Swift there are only initializers, and both should be mapped
to the same Swift initializer (as it is the case with other Foundation
classes). Apparently that does not work correctly, but the result
is identical:
let cal1 = NSCalendar(calendarIdentifier: NSCalendarIdentifierChinese)
let cal2 = NSCalendar(identifier: NSCalendarIdentifierChinese)
print(cal1 == cal2) // true

In Swift 3 there is only one initializer, taking an NSCalendar.Identifier
parameter:
let cal = NSCalendar(identifier: .chinese)

(or the new value type
let cal = Calendar(identifier: .chinese)

which takes an enumeration parameter).
Answer: In Objective-C, there are two renditions, calendarWithIdentifier convenience method that returns autorelease object and initWithCalendarIdentifier that returns a +1 object. The distinction of the autorelease object and the +1 object has little practical implication nowadays (and really only comes into play if you were allocating and releasing many of them inside a loop, which you're unlikely to be doing with this class).
In Swift, they both resolve to init?, the first with a parameter called identifier and the other whose parameter is calendarIdentifier.
Note, in Swift 3, this confusion is eliminated, both converted to init?(identifier:).


Qualtrics - setEmbeddedData

Question: I'm pretty new to javascript, and I'm just trying to do some simple stuff as practice to learn.
I've created two embedded data fields in the survey flow and named them "A1" and "A2." In A1 I have assigned a value in the survey flow but I'm trying to set the value of A2 in the javascript of a question.
Survey Flow
In question 2's javascript I've put a setEmbeddedData statement that isn't working. I'm piping in the choice text in the question from A2 and nothing is coming in.
This is what I've used in the question's javascript...
Any suggestions?
Comment: Please provide enough code so others can better understand or reproduce the problem.
Answer: Two things:

setEmbeddedData() doesn't work with Simple layout.
When you use setEmbeddedData(), you can't pipe the value set until the next survey page

Qualtrics - setEmbeddedData


Elementary geometric characterization of spheres?

Question: I've read the following two theorems.
Theorem. A compact connected metric space whose points are cuts points with the exception of at most two is homeomorphic to the unit interval.
Theorem. A compact connected metric space which becomes disconnected upon removing any two points is homeomorphic to the unit circle.
Are there analogous characterizations for $S^n$ using higher-connectedness, i.e triviality of homotopy groups?
Comment: Well spheres have many non-trivial homotopy groups, and there are many spaces homotopy equivalent to the sphere which are not homeomorphic to it. Up to homeomorphism spheres are the only compact simply-connected manifolds with their homology (this is the generalized Poincare conjecture), and that is not an easy result.
Comment: For a unit circle you also want to demand that the space has no cut points as well.
Answer: In 2-dimensions you might want the Kline sphere characterization theorem.
Answer: In higher dimensions this is very difficult and, I think, there is no simple characterization along the lines of the ones in low dimensions. The main difficulty comes from characterization of compact manifolds among, say, compact metrizable topological spaces. The characterizations of spheres in dimensions 1 and 2  are (implicitly) based on the fact that in these dimensions homology manifolds are the same as topological manifolds. This is far from being true in higher dimensions. Until 1995 there was at least a conjecture describing which homology manifolds are topological manifolds (Cannon's conjecture). If this conjecture were true then topological manifolds  of dimension $\ge 5$ would be characterized as ANRs which are homology manifolds satisfying the "disjoint disk property". Cannon's conjecture was disproved in the paper "Topology of Homology Manifolds"  by J. Bryant, S. Ferry, W. Mio and S. Weinberger (Annals of Math., 1996). Now, as far as I known, there is no even a simple-minded conjecture characterizing topological manifolds and, in particular, spheres, of dimension $\ge 5$. In view of these results, the only (known to me) topological characterization of $S^n$ is the following:
Theorem. Suppose that $X$ is a compact metrizable space. Assume also that $M$ is ANR (an absolute neighborhood retract), is an $n$-dimensional homology manifold, has DDP (disjoint disk property) and $i(X)=1$ where $i$ is Quinn's invariant. Assume also $X-x$ is contractible for some (every) $x\in X$. Then $X$ is homeomorphic to $S^n$, provided $n\ge 5$.
This theorem contains many words (likely) unfamiliar to you, and, depending on your background, you may as well spend 5 years just learning what do they all mean.
Comment: What is the issue with this working in $4$ and $3$? Is recognizing 4-manifolds post Freedman theory really still fundamentally different than in higher dimensions?
Comment: @PVAL: Surgery theory does not work in dimension 4 (and the DDP condition has to be modified, do not know how). In dimension 3, I am not sure. One needs a replacement to DDP. There are examples of ANR homology 3-manifolds which are not manifolds. The first one, I think, is due to Bing (contract a wild arc to a point).


Distribution of the sufficient statistic in the exponential family?

Question: Suppose $\boldsymbol X$ belongs to the exponential family,
$$ f_X\!\left(\,\mathbf{x} ; \boldsymbol \theta\,\right) = h(\mathbf{x}) \, \exp\!\Big(\,\boldsymbol\eta({\boldsymbol \theta}) \cdot \mathbf{T}(\mathbf{x}) - A({\boldsymbol \theta})\,\Big)$$
with $\mathbf{T}(\mathbf{x})$ the  sufficient statistic.
Is there a way to factorize $f_X\!\left(\,\mathbf{x};\boldsymbol \theta\,\right)$ such that
$$f_X\!\left(\,\mathbf{x};\boldsymbol \theta\,\right) = f_T\!\left(\,\mathbf{T};\boldsymbol \theta\,\right) f_{X|T}\!\left(\,\mathbf{x} | \mathbf{T}\right)$$
where $f_{X|T}\!\left(\,\mathbf{x} | \mathbf{T}\right)$ is the distribution of $\boldsymbol X$ conditional on $\mathbf{T}$, and $f_T\!\left(\,\mathbf{T};\boldsymbol \theta\,\right)$ is the marginal distribution of $\mathbf{T}$?
Answer: In a discrete setting, when the sampling space $\mathfrak X^n$ (assuming an iid sample of size $n$ from an exponential family) is finite or countable, the conditional distribution of
$$\mathbb P(\mathbf X_n=\mathbf x_n;\theta\vert T_n(\mathbf X_n)=t_n)= \dfrac{\mathbb P(\mathbf X_n=\mathbf x_n;\theta)}{\mathbb P(T_n(\mathbf X_n)=t_n;\theta)}$$
Hence, using the counting measures on $\mathfrak X^n$ and $T(\mathfrak X^n)$, respectively,
$$f(\mathbf x_n;\theta) = f(\mathbf x_n\vert T_n(\mathbf X_n)=t_n) \times f(t_n;\theta)$$
In the continuous case, the result is somehow a tautology since the choice of the (three) dominating measures is open. To start, we can wlog assume that$$T_n(\mathbf x_n)=\sum_{i=1}^n x_i$$
and that the density with respect to a measure $\lambda^{\otimes n}$ on $\mathfrak X^n$ is
$$f(\mathbf x_n;\theta) = \prod_{i=1}^n h(x_i) \times e^{\theta\cdot T_n(\mathbf x_n) - n A(\theta)}$$
Changing the measure into$$\text d\mu(x) \stackrel{\text{def}}{=} h(x)\,\text d\mu(x)$$leads to the density with respect to the measure $\mu^{\otimes n}$ on $\mathfrak X^n$
$$f(\mathbf x_n;\theta) = e^{\theta\cdot T_n(\mathbf x_n) - n A(\theta)}$$
The joint density of $(T_n(\mathbf X),X_2,\ldots,X_n)$ wrt the measure $\mu_{T_n}\otimes\mu^{\otimes n-1}$ on $T_n(\mathfrak X^n)\times\mathfrak X^{n-1}$ is then
$$f(t_n,x_2,\ldots,x_n;\theta) = e^{\theta\cdot t_n - n A(\theta)}\tag{1}$$
since the Jacobian is equal to one. The marginal density of $T_n(\mathbf X)$ wrt $\mu_{T_n}$ is thus
$$f(t_n;\theta) = e^{\theta\cdot t_n - n A(\theta)}\times \tilde h(t_n)$$
where the last term $\tilde h(t_n)$ is the mass of $$T_n(t_n-\sum_{i\ge 2} x_i,x_2,\ldots,x_n)=t_n\tag{2}$$ under $\mu^{\otimes n-1}$. Changing the measure $\mu_{T_n}$ to the new measure $\xi_{T_n}$ defined by
$$\text d\xi_{T_n} (t)= \tilde h(t)\text d\mu_{T_n}(t)$$
leads to the following density of $T_n(\mathbf X)$ wrt $\xi_{T_n}$:
$$f(t_n;\theta) = e^{\theta\cdot t_n - n A(\theta)}$$
If one defines $\zeta_{t_n}$ as the mass one uniform measure over the slice $$\left\{(x_1,x_2,\ldots,x_n); \ T_n(x_1,x_2,\ldots,x_n)=\sum_{i=1}^n x_i=t_n\right\},$$ the conditional density of $\mathbf X$ conditional on $T_n(\mathbf X)$ is one and
$$f_X\left(\,\mathbf{x}_n;\theta\,\right) = f_{T_n}\!\left(\,t_n; \theta\,\right) f_{X|T=t_n}\!\left(\,\mathbf{x}_n | T_n=t_n\right)$$
when the densities are taken wrt $\mu^{\otimes n-1}$, $\xi_{T_n}$, and $\zeta_{t_n}$, respectively.
(Note: Using $f$ for different densities is an abuse of notation, but avoids an explosion in said notation.)
Answer: To get $f_{T}\!\left(\,\mathbf{T} ; \boldsymbol\theta\right)$, we take the full density and integrate $\mathbf{x}$ out:
\begin{align}f_{T}\!\left(\,\mathbf{T} ; \boldsymbol\theta\right) &=  \int_{{\bf x} : {\bf T(x)} = {\bf T}} f_X\!\left(\,\mathbf{x} ; \boldsymbol \theta\,\right) d {\bf x} \\
&= \exp\!\Big(\,\boldsymbol\eta({\boldsymbol \theta}) \ \mathbf{T} - A({\boldsymbol \theta})\,\Big)
 \int_{{\bf x} : {\bf T(x)} = {\bf T}} h(\mathbf{x}) d {\bf x} \\
&= \exp\!\Big(\,\boldsymbol\eta({\boldsymbol \theta}) \ \mathbf{T} - A({\boldsymbol \theta})\,\Big) h_T({\bf T})
\end{align}
Where
$$h_T({\bf T}) =  \int_{{\bf x} : {\bf T(x)} = {\bf T}} h(\mathbf{x}) d {\bf x}$$
Consequentially, we have
$$  f_{X|T}\!\left(\,\mathbf{x} | \mathbf{T}\right) = \frac{ h({\bf x}) }{h_T({\bf T}({\bf x}))}  $$
Comment: The integral$$\int_{{\bf x} : {\bf T(x)} = {\bf T}} f_X\!\left(\,\mathbf{x} ; \boldsymbol \theta\,\right) \text d {\bf x}$$is not defined when $\text dx$ denotes the Lebesgue measure.


HKCU Sotware In Registry & Malware

Question: In reading about forensics its mentioned that malware could be found in the Software HKCU. My question is if malware installs will Windows definitely put it in this registry section? I always assumed malware could hide anywhere, but what I'm reading makes it seem as if it will be in this location. Does Windows put all installed software here / can it be changed by malware?
Answer: Malware is a malicious piece of code running on a computer.
If by "found in Software HKCU" you refer to the malware's persistence technique, then YES - one of the techniques that malware authors use for persistency is to take advantage of registry keys that will allow their processes to startup when the user is logged in.
"I always assumed malware could hide anywhere, but what I'm reading makes it seem as if it will be in this location"\
Malware can indeed hide itself in different manners, and there is no "requirement" for malware to use the registry for persistence or to hide itself.
"Does Windows put all installed software here" - No.
HKCU stands for HKEY_CURRENT_USER, i.e it contains configuration information for Windows and software specific to the currently logged in user.
Given the right permissions, malware can definitely change keys and values under HKCU.
Hope that helps. If you are interested, I highly recommend Practical Malware Analysis, it's a great book.

HKCU Sotware In Registry & Malware


É possível um input no meio de um print em Python 3?

Question: Algo como um input no meio de um print, é possível?
Estou tentando fazer algo assim:
print (f "Eu quero digitar {input ('')} palavras.")

Se eu precisar de algum módulo pygame ou o que for...
O que eu quero é uma resposta de tipo de entrada entre dois textos como:
QUERO DIGITAR |_ PALAVRAS

| significa o cursor do mouse indicando onde digitar e _ significa o input.
Estou usando o Python 3.

Desde já agradeço a todos pela possível ajuda. Eu acho que as próximas versões do python deveriam implementar isso .. pq é uma boa eu perguntar ao usuário por ex n° de _______ casas
_______ seria onde o usuário Digitaria isso num input.               Seria uma espécie de print(f"eu tenho {input()} ideias")
Comment: Por favor, redija sua pergunta em português uma vez que estamos no [pt.so].
Answer: Cara, pelo o que eu entendi é super simples.
Seria algo do tipo:
input = raw_input()
print("I want to type " + input + " words.")

E se você quer que escrever a primeira parte do texto, parar a execução, ler o input e continuar o texto você pode usar:
print("I want to type ", end="")
input = raw_input()
print(input + " words.", end="")

Mas essa última implementação só irá funcionar em Python 3. Como você mencionou no título que está usando Python 3, então sem problemas :)
Esse último parametro permite que você escolha qual será último caracter, que por padrão é "\n", mas desse jeito que eu mostrei você define para uma string vazia, ou seja, nada.
Comment: a função raw_input não foi renomeada pra input() ? Aqui a raw_input não funciona... Tentei com input e não chegou ao meu resultado.
Por sinal dei uma pesquisada e ela realmente foi renomeada pra input() apenas, ou seja o raw_input não funciona mais, ele fica até irreconhecível no pycharm
Comment: I didn't get what I want yet, the raw_input() function doesn't work in python3.7
Comment: Desculpe por este erro. Fiz de cabeça, sem testar. Mas o importante é passar a idéia hehe ^^
Comment: Mas creio que o comentário do Pedro Heriqu está mais alinhado com o que você esteja procurando...
Answer:
Acho que é isso aqui que você quer:

python
# Definimos o começo e o fim da frase:
começo_da_frase = "Eu quero digitar "
fim_da_frase = "____ palavras"
espaço = len(começo_da_frase)*" "

print(espaço,fim_da_frase,"\r",começo_da_frase,flush=True,end="")
input('') #explicação abaixo

Explicação:
Esse é uma das formas de resolver, não é muito elegante mas foi o que eu consegui pensar rápido aqui.

Então é o seguinte, você quer imprimir:
"Eu quero digitar |___ palavras" e receber uma entrada que será inserida no local marcado com "|".

Logo você precisa voltar na linha.

Então você imprime um espaço para o começo da frase, imprime o final_da_frase, volta ao começo da linha "\r" e imprime o começo_da_frase. Agora você parou o cursor bem no começo do "___", então é só você pedir o input!
Mas atenção! Ao dar print, a função te joga no começo da linha seguinte, evite isso colocando a clausula end = ""
Defeitos da solução:

Ao digitar mais caracteres do que len("____") o texto do usuário começa a apagar o final_da_frase

Observações:

Talvez seja possível resolver o problema que citei com o pacote curses, ele gerencia o prompt te dando maior controle sobre essas coisas, mas é algo avançado demais pra mim haha
O nome do "\r" é Carriage Return, ou CR
Comment: Infelizmente ainda não chegou ao resultado que eu quero (mas sou grato pela ajuda/disposição) enfim, até imaginei que esse flush me ajudaria, eu queria que meu input não paralisasse o print seguinte...
Comment: Então, trabalhar só com a Standard Library vai te dar um pouco de dor de cabeça. o Curses deve resolver seu problema, mas eu não faço a menor ideia de como executar o código, embora isso parece algo bem básico eu não encontrei nenhuma forma elegante de resolver.
Comment: E você deveria pensar em migrar seu código pra algo com uma user interface mais moderna, Kivy é uma ótima library pra começar, principalmente pq te permite exportar pra mobile sem ter que programar infernos em Java.
Comment: Agradeço as dicas. Vou dar uma busca de qualquer forma. Peço que olhe o comentário final do tópico


How to use integral - $x^2$

Question: I want to count integral of $f(x)=x^2$ in range for example $0$ through $10$.
What should I read to do it by myself and apply it to other funcs ?
Answer: First learn differential calculus, then integral calculus. The formula to be used here is :$$\int_{a}^{b} x^{n} \ dx = \bigg[\displaystyle \frac{x^{n+1}}{n+1}\bigg]^{b}_{a}$$
Note: the answer will be $\frac{b^{n+1}}{n+1} - \frac{a^{n+1}}{n+1}$
Comment: Maybe $\bigg[\displaystyle \frac{x^{n+1}}{n+1}\bigg]^{b}_{a}$ = \bigg[\displaystyle \frac{x^{n+1}}{n+1}\bigg]^{b}_{a} or using \bigg| on the right side instead of the brackets.
Comment: I don't know how to put the limits near the bracket. Anyone can tell me how to put it.
Comment: You're welcome (wow, you are quick, I was still polishing my comment)
Comment: Note that it doesn't work for $x^{-1}$

How to use integral - $x^2$


How to prove the convergence of $\lambda_n = \frac{f_{n+1}}{f_n}$?

Question: A question about the fibonacci sequence.
I have a sequence:
$$\lambda_n = \frac{f_{n+1}}{f_n}$$
While $f_n$ is the fibonacci sequence.
I also have the equation: $$ 0 = x^2 - x -1$$
And i know that the two possible values for x are:
$$x= \frac {1\pm \sqrt{5}}{2}$$
(The famous golden ratio)
Let $\alpha$ be the positive solution for the above equation. Let $\beta$ be the negative one.
I want to show that $$\sigma_n = \frac {\lambda_n - \alpha}{\lambda_n - \beta}$$
converges (It does converge against 0 right? Because $\lambda_n$ converges against $\alpha$ But how would i go on proving it?).
I know about Cauchy's convergence criterion, and the definition for limits.. etc.
I don't get how to apply them here. For me, the coherence between the fibonacci sequence and the golden ratio is really hard to understand.
P.S: This is an exercise in analysis 1 (computer science), first term. I have seen questions like: Fibonacci and the algebraic expression $x^2-x-1$
But i can't understand these because i haven't ever seen most of the stuff they do there in our lectures.
Comment: What do you want to prove?That $\lambda_n$ converges or $\sigma_n$?
Comment: do you really mean $(f_{n} + 1)/f_n$, as written, or do you mean $f_{n+1}/f_n$?
Comment: Sorry had a typo there, edited.
Comment: I want to prove that $\lambda_n$ converges in the first place, using $\sigma_n$.
Comment: If i showed that $\sigma_n$ converges, i have shown that $\lambda_n$ converges, right?
Comment: because $|\lambda_n - \alpha|<\epsilon$.
Answer: To prove the convergence, I'll directly compare successive terms of $\lambda_n - \phi$ where $\phi$ is the golden mean (i.e. your $\alpha$). Notice
$$\frac{\lambda_n - \phi}{\lambda_{n-1} - \phi}
= \frac{F_{n+1} - \phi F_n}{F_n - \phi F_{n-1}}\frac{F_{n-1}}{F_n}
= \frac{(1-\phi)F_n + F_{n-1}}{F_n - \phi F_{n-1}}\frac{F_{n-1}}{F_n}\\
\stackrel{\color{blue}{[1]}}{=} \frac{(1-\phi)F_n - F_{n-1}\phi(1-\phi)}{F_n - \phi F_{n-1}}\frac{F_{n-1}}{F_n}
= (1-\phi)\frac{F_{n-1}}{F_n}
$$
Since $F_n$ is increasing, $\left|\frac{F_{n-1}}{F_n}\right| \le 1$. Together with $|1 - \phi| = \phi^{-1} < 1$, we get
$$\left|\frac{\lambda_n - \phi}{\lambda_{n-1} - \phi}\right| < \phi^{-1}
\quad\stackrel{\color{blue}{[2]}}{\implies}\quad
| \lambda_n - \phi | \le \phi^{-(n-1)} |\lambda_1 - \phi| = \phi^{-n}
\to 0\;\text{ as }\; n \to \infty
$$
As a result, $\lim\limits_{n\to\infty} \lambda_n = \phi$.
Update
As an alternate approach, one can compare the successive terms of $\sigma_n$. Notice
$$\begin{align}
\sigma_n &= \frac{\lambda_n - \alpha}{\lambda_n - \beta}
 = \frac{F_{n+1} - \alpha F_n}{F_{n+1} - \beta F_n}\\
&= \frac{(1-\alpha)F_n + F_{n-1}}{(1-\beta)F_n + F_{n-1}}
 = \frac{(1-\alpha)F_n - \alpha(1-\alpha)F_{n-1}}{(1-\beta)F_n - \beta(1-\beta)F_{n-1}}\\
&= \frac{1-\alpha}{1-\beta}\frac{\lambda_{n-1}-\alpha}{\lambda_{n-1}-\beta}\\
&= \frac{\beta}{\alpha}\sigma_{n-1}
\end{align}
$$
Since $\left|\frac{\beta}{\alpha}\right| < 1$, we find
$$\lim_{n\to\infty} \sigma_n \stackrel{\color{blue}{[2]}}{=} \lim_{n\to\infty} \left(\frac{\beta}{\alpha}\right)^{n-1} \sigma_1 = 0
\quad\implies\quad
\lim_{n\to\infty} \lambda_n = \lim_{n\to\infty} \frac{\alpha-\beta\sigma_n}{1-\sigma_n} = \frac{\alpha - \beta\cdot 0}{1-0} = \alpha$$
Notes

$\color{blue}{[1]}$ - We are using the identity $1 = -\phi(1-\phi)$ here.
$\color{blue}{[2]}$ - We are using the fact $|\lambda_n - \phi|$ is equal to
the product of $|\lambda_1 - \phi|$ with a telescoping products of ratios. More precisely,
$$|\lambda_n - \phi| =
\underbrace{\left|\frac{\lambda_n - \phi}{\lambda_{n-1} - \phi}\right|}_{ < \phi^{-1}}
\underbrace{\left|\frac{\lambda_{n-1} - \phi}{\lambda_{n-2} - \phi}\right|}_{ < \phi^{-1}}
\cdots
\underbrace{\left|\frac{\lambda_{2} - \phi}{\lambda_{1} - \phi}\right|}_{ < \phi^{-1}}
|\lambda_1 - \phi| < \phi^{-(n-1)}|\lambda_1 - \phi|$$
For the same sort of reasoning, we have $\sigma_n = \frac{\beta}{\alpha} \sigma_{n-1}$ for all $n > 1$ implies $\sigma_n = \left(\frac{\beta}{\alpha}\right)^{n-1}\sigma_1$.
Comment: (referring to first approach) Thank you, i really appreciate your help. Sorry to be a pain, But there is two things i don't understand : 1. How do you get from the 3rd to the fourth transformation step? And 2. I can't follow what you did in the final conclusion, i don't understand why the left side implies the right side..
Comment: The second approach makes more sense to me - i still have trouble understanding why $|\frac{\beta}{\alpha}|<1$ implies that the limit of $\sigma_n$ is 0, as we only have the recursive sequence of $\sigma_n$.
Comment: @FalcoWinkler I've added some notes to explain some fine points. Is it clear now?
Comment: YES yes yes, with those notes it is more clear now. I will still have to work my way through it, but thanks for the detailed answer! You should definitely get more upvotes on that.
Comment: Since $\sigma_1 = -\alpha^{-2}$ and $\left( \frac{\beta}{\alpha} \right) = -\alpha^{-2}$ this answer can be simplified to $$(-1)^n \alpha^{-2n}$$. As in the third answer below.
Answer: We have:
$$\sigma_n = \frac{f_{n+1}-\alpha\,f_n}{f_{n+1}-\beta\, f_n}=1+\frac{(\beta-\alpha)\,f_n}{f_{n+1}-\beta\,f_n}=1+\frac{\beta-\alpha}{\frac{f_{n+1}}{f_n}-\beta}$$
and since $\lim_{n\to +\infty}\frac{f_{n+1}}{f_n}=\alpha$, our limit ($\lim_{n\to +\infty} \sigma_n$) equals:
$$1+\frac{\beta-\alpha}{\alpha-\beta}=0.$$
Comment: But have i proven yet that the limit of $\lambda_n$ is $\alpha$?
Comment: @FalcoWinkler: if not, it is worth proving it :)
Comment: Thanks for your efforts so far - but proving $\lambda_n$ convergent is what i have to do. The task says we should do that while looking at the sequence $\sigma_n$. Do you know what i mean?
Answer: $$
f_n = \frac{\alpha^n-\beta^n}{\sqrt{5}}
$$
where $\alpha = \frac{1 + \sqrt{5}}{2}$ and $\beta = \frac{1 - \sqrt{5}}{2} = -\frac{1}{\alpha}$.
A bit of algebra gives
$$
\lambda_n = \frac{\alpha^{n+1}-\beta^{n+1}}{\alpha^n-\beta^n}
$$
$$
\sigma_n =\frac{\alpha\beta^b-\beta^{n+1}}{\alpha^{n+1}-\beta\alpha^n}= \left(\frac{\beta}{\alpha}\right)^n=(-1)^n\alpha^{-2n}
$$
And since $|\alpha| > 1$ this converges to zero.


searching an element in list of list

Question: I have a list like:
list=[[lsn,tid,status,type,item,AFIM,BFIM],[1,1,Active,Read,X,-,-],[2,1,Active,Write,X,2,0],....and so on]

Now I have one variable
tid=1

and I want to search that list in 'list' where tid matches and status should be 'Write'. I was trying like this but no result at all.....
for id, stat in list/enumerate(list):
    if id == tid and stat == 'Write':
        print list

Does splitting the list help??
Comment: You should consider using a list of dictionaries rather than list of lists. You've effectively got key-value pairs.
Comment: Also don't call your variable `list` as it masks the builtin.
Comment: Thanks for the suggestion. I just edited to post here otherwise i'm aware of that.Thanks any ways.
Comment: what is `list/enumerate`?
Comment: it means like I have tried with both ways list and enumerate(list)...
Apologies for any confusion.
Answer: Do you mean something like this?
l = [["lsn","tid","status","type","item","AFIM","BFIM"],
     [1,1,"Active","Read","X","-","-"],
     [2,1,"Active","Write","X","2","0"]]

for row in l:
    if row[1] == 1 and row[3] == 'Write':
        print(row)

# will print ...
# [2, 1, 'Active', 'Write', 'X', '2', '0']

You could also use namedtuples:
import collections
Row = collections.namedtuple('Row', 'lsn tid status type item AFIM BFIM')

for row in map(lambda row: Row(*row), l):
    if row.tid == 1 and row.type == 'Write':
        print(row)

# will print ...
# Row(lsn=2, tid=1, status='Active', type='Write', item='X', AFIM='2', BFIM='0')

Comment: This should work but dictionary is the best way to go about it. This will cause the loop to also iterate the first list. Change `"tid"` to 1 and `"type"` to `"Write"` to see the effect.
Comment: @Yax, the header could be skipped easily by using `l[1:]` instead of `l` in the loop, or not?
Answer: No, splitting won't help really.
You could use list comprehensions and dynamic named tuples for this:
from collections import namedtuple

lst = [["lsn","tid","status","type","item","AFIM","BFIM"],
       [1,1,"Active","Read","X","-","-"],
       [2,1,"Active","Write","X","2","0"]]

Data = namedtuple('Data', lst[0])
rows = [Data(*row) for row in lst[1:]]
print [data for data in rows if data.tid == 1 and data.type == 'Write']

# Prints [Data(lsn=2, tid=1, status='Active', type='Write', item='X', AFIM='2', BFIM='0')]

Notes

As someone's already mentioned, better not to call variables after builtins like list - it leads to confusion or bugs usually.

searching an element in list of list


How to give viewers custom CSS option

Question: I am looking for a solution to a kind of odd problem. I am creating a website whose intended purpose is to be embedded in to other peoples websites using an iframe. I want the people who embedd the iframe to be able to customize the CSS of my website. I do not want the viewer of the iframe to be able to customize the CSS but the embedder. I am not sure how I would go about doing that. Any suggestions?
Comment: We do this already for our product which adds a toolbar to the sites of hotels and makes it possible for their customers to make/cancel reservations, etc. We have a pre-defined set of CSS rules which are allowed to be customized which the hotel owners can edit in their profile.
Comment: you can pass some properties through the iframe url. Ex: example.com/?color=blue&size=2&..., you can retrieve those values in the iframe and customize the css
Comment: Depends on how much free space you want to give the client, can he change everything or just specified parameters? Is PHP an option?
Comment: I was thinking about something along the lines of the client being able to set {cssSrc = '/iframe.css'} in the iframe html. I don't think the iframe url would be really efficient. I expect them to have complete control. How would you go about doing it with PHP?
Answer: How I would handle this is to have the user be able to provide a get parameter to select the css file form a server, e.g.
<code>http://www.YourSite.com/page/?css-file=http://www.site.com/path/to/file.css
</code>
And based on the get parameter your server(or the client) would (using Django, php, or possibly in the client using javascript) load the provided css file.
Comment: This only solves the problem if I have predefined CSS files, Have the client Host a CSS file on a sharing site, or only want them to customize a few aspects of the site like background.
Comment: My bad I thought you meant you provided preset styles. Very similar concept, just have them provide the css file to load. Answer edited

How to give viewers custom CSS option


Custom user profile fields, not editable by user

Question: I've created some custom user profile fields but I don't want to let the user change those fields when he is editing his profile. These fields should only be changed by the site admin.
How can I do that? Thanks
Answer: You could try looking at the Field Permissions module.  Simply don't allow editing of your specific fields for the role that the registering/registered user has.


Linux ports become unavailable

Question: We have some Ubuntu 18.04 servers with hard-to-diagnose problems that have some similarities. The servers run a hosted VOIP PBX service with various component applications.

Kamailio occasionally starts giving "Lost connection to MySQL" errors. (these connections are TCP)
Kamailio occasionally gives "more than 'max_user_connections' active connections" MySQL errors. (these connections are TCP)
Asterisk occasionally starts giving "couldn't allocate a port for RTP" errors. (these connections are UDP)

Although there are other possible explanations individually (and we've looked into those), they could conceivably all be caused by the same one problem of ports not being released back to the available pool after they've been used.
Would anyone have any hints about where to look to find out if this theory is true, or possible solutions if it is? Thanks in advance.
Comment: The simpler explanation could be that your *asterisk user* runs out of available file descriptors, set too low in `/etc/limits.conf` or some file included into it. Before thinking there are problems in the system, diagnose; in particular, `lsof` for that user and `ss -lnptu` could reveal is there really no "unused" ports left or you hit the said limit.
Comment: Thanks Nikita, using "lsof" showed ports were in use, but the question is why. We have many other servers with similar software which don't have the issue. All these problems happen to just one group of servers, and none on any others. That's why we're looking at what could be a system-wide issue on these servers, affecting more than one application on those servers, for example if something could prevent ports from being released.
Comment: *All 65534* ports were in use or only the subset that was configured in the Asterisk or only 1024 or whatever the limit is set for the asterisk user? I asked you to do `lsof` exactly to distinguish those cases.
Comment: @DavidCunningham  Additional DB information request from FAILING srv, please.
RAM size, # cores, any SSD or NVME devices on MySQL Host server?
Post TEXT data on justpaste.it and share links.
From your SSH login root, Text results of:
A) SELECT COUNT(*), sum(data_length), sum(index_length), sum(data_free) FROM information_schema.tables;
B) SHOW GLOBAL STATUS;    after minimum 24 hours UPTIME
C) SHOW GLOBAL VARIABLES;
D) SHOW FULL PROCESSLIST;
E) STATUS;  not SHOW STATUS, just STATUS;
G) SHOW ENGINE INNODB STATUS;
for server workload tuning analysis to provide suggestions.
Comment: From one failing server - please,
Post TEXT data on justpaste.it and share the links.
Additional very helpful OS information includes - please,
htop            1st page, if available, TERMINATE,
top -b -n 1  for most active apps,
top -b -n 1 -H  for details on your mysql threads memory and cpu usage,
ulimit -a       for list of limits,
iostat -xm 5 3 for IOPS by device & core/cpu count,
df -h  for Used - Free space by device,
df -i  for inode info by device,
cat /proc/meminfo includes VMallocUused,
for server workload tuning analysis to provide suggestions.
Answer: Check below links as you haven't shared complete logs or what you have tried to fix it, so I am sharing similar issue.

Lost connection to MySQL -- Lost Connection
More than 'max_user_connections' active connections -- max_user_connections
Couldn't allocate a port for RTP -- Port

I am sure these links will give you pointer to either towards solution or improve your question.
Comment: Hello, thank you for that, however my question is not about each one individually. I'm asking about the possibility that there is some system-wide problem about ports not being released. We manage many other servers with similar software, and all these problems happen to just one group of servers, and none on any others. That's why we're looking at what could be a system-wide issue on these servers, affecting more than one application on these servers.
Comment: If you check each links, it shows many problems with solution. If you have any config management tool which is managing config across your environment then problem also replicated. These issues are generic and can be related to software or os settings.

Linux ports become unavailable


Python Stuck Calculating

Question: I am trying to solve a problem using python, and I need to calculate :
r =(1^2|~4)**((5&9^3)|3*8**9)
However, the computer is taking forever to finish that operation. Any clue on how to solve this?
Simpler = -5**402653186
SPECS :
OS : Ubuntu 18.04
RAM : 8 Gig
CPU : Intel i5 8Gen
Answer: The number you're trying to calculate is very large. -1.45992917087860574535892544169158544350135939488 × 10^281442499 to be precise according to wolfram-alpha. While python longs can be of unlimited length and expand to fill memory it is just a calculation that would take a super long time, try using htop, it should show that ram usage is constantly increasing. You should reconsider on why you are calculating numbers so large.
Comment: Hampton Moore is quite right. You're using the wrong tool for the task at hand (or possibly have specified the wrong task). You might be happier using this library: https://gmplib.org/

Python Stuck Calculating


What's it called when the Melody and Harmony are half a measure out-of-sync?

Question: As an example in caveman speak, the melody goes ONE-2-3-4-ONE-2-3-4, and the harmony goes 1-2-THREE-4,1-2-THREE-4.
I'm not sure this is actually an example of what I'm talking about, but in the intro of

 (Zaveid's battle theme, 12 seconds in), there's a melody going, and when the bass kick harmony is added on, it seems a half-measure out-of-sync with what the melody is doing. It's an interesting effect, and I was wondering what it's called. That being said, I'm sure if, for the example I gave, I listened to it/analyzed it more closely, there isn't a desync between the harmony and melody. Still, I'd like an answer to the question, as well as a prototypical example.
P.S.: I guess a similar way to refer to the phenomenon is that the melody goes 1-2-THREE-4-1-2-THREE-4 (the emphasis seems to happen midway through the measure)
Answer: I think what's going on here is a pet peeve of mine as a listener. Once the kick comes in, it's very clear where the beats are. In the preceding measures, the melodic material is just the same, but it's harder to tell where the beats are. The riff plays on beats one and four, but on beats two and three it has a rest on the exact moment of the beat, instead playing a moment later. In rhythmic syllables, if you count "1 e & a," you might say that it plays on the "e" of beats two and three: "ONE E (and a two) E (and a three) E (and a) FOUR E AND A." Or, notated, this:

With no other instruments providing a strong sense of the beat, it's very disorienting on first listen. After all, we don't know that it's notated like this; all we get is bits of sound on a timeline. We wonder whether those isolated C and B are in fact beats, and then are thrown off by the final full set of 16ths. Once the kick comes in, it's not quite where we expect it and it takes a few seconds to calibrate.
There isn't a term, per se, for the cognitive dissonance we feel between the unclear (misperceived?) meter of the intro and the clarity of a few bars later, and I can't think of a good term for a contrast between a voice with simple rhythm and one with a more complex one. But there might be good terms to describe the guitar part. One might use "syncopated," but that could be confusing. Syncopation is often about emphasizing weak beats, or "stretching" simple notes so that they begin early or end late; think ragtime. I think "displacement" might be the most useful word. Google "beat displacement" or "rhythmic displacement" and you find a lot of videos and blogs, like this one, talking about the idea of shifting notes to be ahead of or behind the beat.
So it's not a single handy phrase, but maybe the best way to describe this is "The guitar part displaces the notes on the second and third beat, delaying them by a sixteenth note. This creates some metric ambiguity until the kick drum enters, marking each beat directly."
You mention a "prototypical example": perhaps the simplest and best example of the potential confusion between offbeat and onbeat was mentioned in a comment thread linked above, "She's a Woman" by the Beatles:

The only sonic information we get at the outset is the regularly-spaced guitar chords. Given no other information, we are forced to perceive them as beats. But once the drums enter they're revealed to be offbeats.
Similarly, my nemesis for decades has been this track by AfroCelt Sound System:

Around the 4:00 mark most instruments drop out and there's no strong sense of the beat. Then the vocalist comes back with a repeated "Cha! Cha!," and the guitar has a choppy strum at the same time. It's near impossible not to hear these strums and chants as being on the beat. But when everybody drops back in at 4:23 they're revealed to be offbeats and we feel like we stepped off a moving sidewalk on the wrong foot.
Comment: I always thought this one was easy, but once when I was depping on drums with a function band it turned out none of them had ever figured out the entire track starts on the 2, so they were all counting a 3/4 bar as the main song comes in, thinking the claps & kick were on the 1. It took me a while to get it through their heads... [Rose Royce, Car Wash](https://www.youtube.com/watch?v=eB0aROCl530)
Comment: I don't see why _syncopation_ isn't the description of the anime tune. The down beat seemed clear to me even before the kick bass was in. The Beatles example does seem to present something else, both because the guitar strokes are _evenly spaced_ and isolated for the very beginning. At the very beginning there really isn't context to hear weak/strong beat. But it's also a sort of arranging trick of removing the other instruments to create the ambiguity. Once all the parts are going the guitar is just syncopated backbeat placement.
Comment: @Tetsujin, Kings of Leon, Charmer, is really interesting. It's so hard to not hear the snare as backbeat in rock. The song's rhythm is really disorienting.
Comment: And this one - all the clues are there (the bass starts right on the one, so you've no real excuse;) but then the crash on *4 and*  throws you every time, especially as the snare is on-beat, not off like you might expect. Takes a while to get the hang of it. [Kings of Leon, Charmer](https://www.youtube.com/watch?v=yCd1vXsvkV4) I do like this band for their intentional 'mis-cues' every so often.
Comment: @MichaelCurtis - just for fun, try this one. There's no timing difficulty in this one, instead they throw you with the key. It's all a really simple 3-chord turnaround in E, pedal E all the way… but it's not. Melody comes in on  C, with bass on A. Messes with your head a bit on first listen. https://www.youtube.com/watch?v=GOAu1HzChlY Much softer song than the other one, too.


Falha no teste - setup.ts

Question: Galera,
Estou tentando rodar um teste do componente App, no entanto, o jest está interpretando o setup.ts como um teste.
Já apontei ele como um setup no package.json, mas não funciona.
Setup.ts
import Enzyme from 'enzyme';
import Adapter from 'enzyme-adapter-react-16';

Enzyme.configure({ adapter: new Adapter() });

Package.json
{
  "name": "client",
  "version": "0.1.0",
  "private": true,
  "dependencies": {
    "@babel/core": "7.1.6",
    "@svgr/webpack": "2.4.1",
    "@types/axios": "^0.14.0",
    "@types/bootstrap": "^4.2.0",
    "@types/enzyme-adapter-react-16": "^1.0.3",
    "@types/jest": "23.3.12",
    "@types/node": "10.12.18",
    "@types/react": "16.7.18",
    "@types/react-dom": "16.0.11",
    "@types/react-redux": "^6.0.12",
    "@types/react-router-dom": "^4.3.1",
    "@types/reactstrap": "^6.4.4",
    "babel-core": "7.0.0-bridge.0",
    "babel-eslint": "9.0.0",
    "babel-jest": "23.6.0",
    "babel-loader": "8.0.4",
    "babel-plugin-named-asset-import": "^0.3.0",
    "babel-preset-react-app": "^7.0.0",
    "bfj": "6.1.1",
    "bootstrap": "^4.2.1",
    "case-sensitive-paths-webpack-plugin": "2.1.2",
    "chalk": "2.4.1",
    "css-loader": "1.0.0",
    "dotenv": "6.0.0",
    "dotenv-expand": "4.2.0",
    "enzyme": "^3.8.0",
    "enzyme-adapter-react-16": "^1.7.1",
    "eslint": "5.6.0",
    "eslint-config-react-app": "^3.0.6",
    "eslint-loader": "2.1.1",
    "eslint-plugin-flowtype": "2.50.1",
    "eslint-plugin-import": "2.14.0",
    "eslint-plugin-jsx-a11y": "6.1.2",
    "eslint-plugin-react": "7.11.1",
    "file-loader": "2.0.0",
    "fork-ts-checker-webpack-plugin-alt": "0.4.14",
    "fs-extra": "7.0.0",
    "html-webpack-plugin": "4.0.0-alpha.2",
    "identity-obj-proxy": "3.0.0",
    "jest": "23.6.0",
    "jest-pnp-resolver": "1.0.1",
    "jest-resolve": "23.6.0",
    "mini-css-extract-plugin": "0.4.3",
    "optimize-css-assets-webpack-plugin": "5.0.1",
    "pnp-webpack-plugin": "1.1.0",
    "postcss-flexbugs-fixes": "4.1.0",
    "postcss-loader": "3.0.0",
    "postcss-preset-env": "6.3.1",
    "postcss-safe-parser": "4.0.1",
    "react": "^16.7.0",
    "react-app-polyfill": "^0.2.0",
    "react-dev-utils": "^7.0.1",
    "react-dom": "^16.7.0",
    "react-redux": "^6.0.0",
    "react-router-dom": "^4.3.1",
    "react-test-renderer": "^16.7.0",
    "reactstrap": "^7.0.2",
    "redux": "^4.0.1",
    "redux-thunk": "^2.3.0",
    "resolve": "1.8.1",
    "sass-loader": "7.1.0",
    "style-loader": "0.23.0",
    "terser-webpack-plugin": "1.1.0",
    "typescript": "3.2.2",
    "url-loader": "1.1.1",
    "webpack": "4.19.1",
    "webpack-dev-server": "3.1.14",
    "webpack-manifest-plugin": "2.0.4",
    "workbox-webpack-plugin": "3.6.3"
  },
  "scripts": {
    "start": "node scripts/start.js",
    "build": "node scripts/build.js",
    "test": "node scripts/test.js"
  },
  "eslintConfig": {
    "extends": "react-app"
  },
  "browserslist": [
    ">0.2%",
    "not dead",
    "not ie <= 11",
    "not op_mini all"
  ],
  "jest": {
    "setupTestFrameworkScriptFile": "<rootDir>/__tests__/setup.ts",
    "collectCoverageFrom": [
      "src/**/*.{js,jsx,ts,tsx}",
      "!src/**/*.d.ts"
    ],
    "resolver": "jest-pnp-resolver",
    "setupFiles": [
      "<rootDir>/__tests__/setup.ts",
      "react-app-polyfill/jsdom"
    ],
    "testMatch": [
      "<rootDir>/__tests__/**/*.{js,jsx,ts,tsx}"
    ],
    "testEnvironment": "jsdom",
    "testURL": "http://localhost",
    "transform": {
      "^.+\\.(js|jsx|ts|tsx)$": "<rootDir>/node_modules/babel-jest",
      "^.+\\.css$": "<rootDir>/config/jest/cssTransform.js",
      "^(?!.*\\.(js|jsx|ts|tsx|css|json)$)": "<rootDir>/config/jest/fileTransform.js"
    },
    "transformIgnorePatterns": [
      "[/\\\\]node_modules[/\\\\].+\\.(js|jsx|ts|tsx)$",
      "^.+\\.module\\.(css|sass|scss)$"
    ],
    "moduleNameMapper": {
      "^react-native$": "react-native-web",
      "^.+\\.module\\.(css|sass|scss)$": "identity-obj-proxy"
    },
    "moduleFileExtensions": [
      "web.js",
      "js",
      "web.ts",
      "ts",
      "web.tsx",
      "tsx",
      "json",
      "web.jsx",
      "jsx",
      "node"
    ]
  },
  "babel": {
    "presets": [
      "react-app"
    ]
  },
  "devDependencies": {
    "react-scripts": "^2.1.3"
  }
}

App.test.ts
import React from 'react';
import { shallow } from 'enzyme';
import App from '../src/App';

describe('Testando o App Component', () => {
  it('Deve renderizar corretamente', () => {
    const wrapper = shallow(<App />);

    expect(wrapper).toMatchSnapshot();
  });
});

Comment: Amigo, evite colocar imagens de texto. É muito ruim de ler, e fica difícil de tentar reproduzir o comportamento localmente. Procura usar as ferramentas de formatação para postar o código e os erros. Isso ajuda a comunidade a te ajudar...
Comment: Obrigado pela dica, já ajustei!
Answer: Você precisa informar ao jest para ignorar o seu setup.ts. Tente adicionar o seguinte no seu package.json
...
"jest": {
    "modulePathIgnorePatterns": [
      "__tests__/setup.ts"
    ]
}

https://jestjs.io/docs/en/configuration.html#modulepathignorepatterns-array-string

Falha no teste - setup.ts


Trouble Identifying Counting Problem Formula?

Question: Would this be the correct formula for the counting problem
Partition with Identical Items
$$
        \begin{pmatrix}
        n \\
        r  \\
        \end{pmatrix}=  \begin{pmatrix}
        n-1 \\
        r  \\
        \end{pmatrix} + \begin{pmatrix}
        n-1 \\
        r-1  \\
        \end{pmatrix}  \
$$
Moreover would anyone know a good example that might demonstrate a partition with Identical items?
Answer: I am a member of a group of $n$ people in a room, of whom $r \le n$ will be awarded
one of $r$ identical prizes. Number of ways: ${n \choose r}.$
But I am interested in whether I will get a prize. There are two
cases:
I do not win a one of the prizes: Number of ways: ${n-1 \choose r}.$
Send me out of the room. Award the $r$ prizes among the $n-1$ people remaining.
I win one of the prizes: Number of ways: ${n-1 \choose r-1}.$
Start by giving me my prize. There are $n-1$ remaining people and $r-1$
remaining prizes.
Add the number of ways for the two cases to get the number of ways overall.
Note: This identity is the basis of 'Pascal's triangle'. (With no
disrespect to Pascal, there are reports of Indian, Arab, and Chinese manuscripts
showing this triangular configuration of numbers from many hundreds of
years before Pascal, some with no obvious indication of purpose.)
Answer: For an example:
Suppose you had to choose a committee of 4 people, from a group of 7 people. Call these 7 people A, B, C, D, E, F, and G. Then you can choose this committee in ${7}\choose{4}$ ways. Another way you can calculate this is to split it up into two cases:
Case 1: A is part of the 4-person committee. There are ${6}\choose{3}$ ways to choose the other 3 people from the remaining 6 people to form the committee.
Case 2: A is not part of the 4-person committee. There are ${6}\choose{4}$ ways to choose the 4 people that make up the committee from the remaining 6 people.
We see that Case 1 and Case 2 account for all the 4-person committees once and only once. This is an example showing that:
$${{7}\choose{4}} = {{6}\choose{4}} + {{6}\choose{3}}$$
Comment: Then I presume my analysis was indeed correct, and the formula you used for your example is the one, I have shown above?
Comment: Yes - your formula is correct. I don't know what it's called though.