prime decomposition in galois extensions

Question: Suppose that K is a finite extension over $\mathbb{Q}$. Let $p$ be a prime in $\mathbb{Q}$, let $p\mathcal{O}_K=\mathfrak{P}_1\ldots\mathfrak{P}_n$ be its prime decomposition in $\mathcal{O}_K$, then is it true that any prime ideal in $\mathcal{O}_K$ above $p$ is a factor in the decomposition of $p$?
Comment: In a word, yes.
Answer: Yes.  I suppose that the definition of a prime ideal $\mathcal{P}$ being "above $p$" you are using is $\mathcal{P} \cap \mathbb{Z} = (p)$.  From this it is clear that if
$\mathcal{P}$ lies above $p$, then it contains $p\mathbb{Z}$, and -- since it is an ideal -- hence also $p \mathcal{O}_K$.  But recall that in a Dedekind domain "to contain is to divide", hence $\mathcal{P}$ divides $p\mathcal{O}_K$ and appears in the (unique!) prime factorization of $\mathcal{O}_K$.
Note that this does not require that $K/\mathbb{Q}$ be Galois (as appears in the title but not the body of the question), and it has nothing to do with algebraic number fields per se: in general, for a finite extension of Dedekind domains $S/R$, the prime ideals of $S$ lying over a given prime $\mathfrak{p}$ of $R$ are exactly the ones appearing in
the factorization of $\mathfrak{p}S$.
Comment: Moreover, a finite field extension is not necessarily a Galois extension.
Comment: And we can in fact find an ideal such that the product of the ideal $\mathfrak{P}$ and that ideal is exactly the ideal $\mathfrak{p}$ if the inclusion holds to be true.
Answer: HINT $\rm\ \ P \supset \mathfrak{P}_1\ldots\mathfrak{P}_n\ \Rightarrow\ P \supset \mathfrak P_i\ $ for some $\rm\:i\:.\ $ This is true for any prime ideal $\rm\ P\ $ in any ring. Further $\rm\ P = \mathfrak P_i\ $ when the $\ \mathfrak P_i\ $ are maximal, e.g. in one dimensional domains, i.e. domains where nonzero prime ideals are maximal.


linux shell rotating script (not a "log rotate" script)

Question: I have a directory that I want to archive. A rotate archive. Never more than 8 files, and each file would have the date of archive in its name. Example:
1_2010_08_01_17h35m26s_archive.tar.bz2
2_2010_08_02_17h34m12s_archive.tar.bz2
3_2010_08_03_17h35m13s_archive.tar.bz2
4_2010_08_04_17h35m24s_archive.tar.bz2
5_2010_08_05_17h34m57s_archive.tar.bz2
6_2010_08_06_17h35m29s_archive.tar.bz2
7_2010_08_07_17h35m13s_archive.tar.bz2
8_2010_08_08_17h35m18s_archive.tar.bz2

And the next archive would delete the 8th file, rename every file to (n+1) then create the new one with name like 1_yyyy_mm_dd_HHhMMmSSs_archive.tar.bz2
NB: I've already looked to some logrotate scripts but none of them to exactly this.
Any idea where I should look?
Thanks again
Answer: With a custom shell script. You should only translate what you write above in shell command. Here you can find a good beginners guide on shell scripting.
Comment: Thanks for the link, I thought that someone else in the whole world may already have had such a need a I could find such a script. I'll check your answer if I can't find a script that does it and I end up writing my own... Thanks again
Answer: It doesn't fit your request entirely, but logrotate configured with dateext rotates files like this:
mainlog-20100720.gz
mainlog-20100721.gz
mainlog-20100722.gz
mainlog-20100723.gz
mainlog-20100724.gz
mainlog-20100725.gz
mainlog-20100726.gz

Digest from man logrotate:
Archive old versions of log files adding a daily extension like YYYYMMDD instead of simply adding a number.


Trouble chaining HTTP requests in Node/Javascript

Question: I'm attempting to recreate a Python script I wrote in Node/js and I'm having trouble wrapping my head around the asynchronous/callback way of it all.
The script is fairly simple and uses two basic HTTP requests to eBay's API.  The first request gets a list of resulting item ids, then the second request gets specific information on each item (description/listing information etc).  In Python this was fairly simple and I used a simple loop.  It wasn't fast by any means, but it worked.
In javascript, however, I'm struggling to get the same functionality.  My code right now is as follows:
var ebay = require('ebay-api');
var params ={};

params.keywords = ["pS4"];
var pages = 2;
var perPage = 2;

ebay.paginateGetRequest({

serviceName: 'FindingService',
opType: 'findItemsAdvanced',
appId: '',
params: params,
pages: pages,
perPage: perPage,
parser: ebay.parseItemsFromResponse
},

function allItemsCallback(error,items){
    if(error) throw error;

    console.log('FOUND', items.length, 'items from', pages, 'pages');

    for (var i=0; i<items.length; i++){

        getSingle(items[i].itemId);

    }
}

);

function getSingle(id){

console.log("hello");
ebay.ebayApiGetRequest({

    'serviceName': 'Shopping',
    'opType': 'GetSingleItem',
    'appId': '',

    params: {
    'ItemId': id ,
     'includeSelector': 'Description'
    }

},
    function(error, data) {
        if (error) throw error;
        console.dir(data);  //single item data I want

    }
);
}

This is one attempt of many, but I'm recieving "possible EventEmitter memory leak detected" warnings and it eventually breaks with a "Error:Bad 'ack' code undefined errorMessage? null".  I'm fairly sure this just has to do with proper utilization of callbacks but I'm unsure how to properly go about it.  Any answers or help would be greatly appreciated.  I apologize if this isn't a good question, if so please let me know how to correctly go about asking.
Comment: Have a look at using something like [tag:node-async] to do this - it can handle the loops for you and manage the completion callback.
Comment: my understanding was that the request would be be processed -> generates a response -> callback is called -> 2ndRequest is processed for each item.  Is that not the general dataflow?
Comment: No.. writing out an answer that describes it.
Comment: welp.. sorry I'm an intern trying to learn as much as I can and I'm unfamiliar with web development in general haha
Answer: Node.js's asynchronous event chain is built on callbacks. Rather than:
getSingle(items[i].itemId);

You'll need to write a callback into that function that executes once the parent function is complete:
getSingle(items[i].itemId, function(err, data) {
     // now you can access the data
});

And because ebay.ebayApiGetRequest is a lengthy function, the callback that tells its parent function that it's done must be called after that completes, like so:
ebay.ebayApiGetRequest({
        //
    },
    function(error, data) {
        callback(error, data);
    }
);

But of course, if the parent function getSingle doesn't support a callback, then it won't go anywhere. So you'll need to support a callback param there as well. Here's the full script, rewritten using the event-driven callback model:
var ebay = require('ebay-api');
var async = require('async');
var params = {};

params.keywords = ["pS4"];
var pages = 2;
var perPage = 2;

ebay.paginateGetRequest({
        serviceName: 'FindingService',
        opType: 'findItemsAdvanced',
        appId: '',
        params: params,
        pages: pages,
        perPage: perPage,
        parser: ebay.parseItemsFromResponse
    },
    function allItemsCallback(error, items) {
        if (error) throw error;

        console.log('FOUND', items.length, 'items from', pages, 'pages');

        async.each(items, function(item, callback) {
            getSingle(item.itemId, function(err, data) {
                callback(err, data);
            });
        }, function(err, results) {
            // now results is an array of all the data objects
        });
    }
);

function getSingle(id, callback) {
    console.log("hello");
    ebay.ebayApiGetRequest({
            'serviceName': 'Shopping',
            'opType': 'GetSingleItem',
            'appId': '',
            params: {
                'ItemId': id,
                'includeSelector': 'Description'
            }
        },
        function(error, data) {
            if (error) throw error;
            console.dir(data); //single item data I want
            callback(error, data);
        }
    );
}

Comment: I feel like a degree really just helps one better understand google results :P
Comment: This was very helpful, thank you for the clear explanation.  I apologize for my ignorance, the world of node is a whole new beast for me.
Comment: Haha! Don't worry, it's a lot to wrap your head around ;)
Comment: I'm still in that "intern realizing how much college didn't teach" phase, but I appreciate the help!
Comment: Honestly, the tech scene changes faster than colleges/universities can keep up anyway!


Composer using old JSON for contrib module?

Question: I maintain skilling, a contrib module. This...
composer require drupal/skilling

... reports...
[RuntimeException]
  Could not load package drupal/skilling in https://packages.drupal.org/8: [UnexpectedValueException] Could not parse version constraint ~1.0@alpha2: Invalid version string "~1.0@alpha2"
[UnexpectedValueException]
  Could not parse version constraint ~1.0@alpha2: Invalid version string "~1.0@alpha2"
An older version of composer.json did use the string "~1.0@alpha2", but it was removed a while ago. Download the module's zip from D.O, and there is no such string in the file set once the zip file is expanded.
BTW, use the zip file, or Git the source files into contrib/modules, and Drupal installs everything just fine. It's just the composer install that's the problem.
I tried composer clearcache, but no dice. Using -vvv on 'composer require' didn't give me any info that I could interpret. Looking at composer's cache shows Strange Things. The file $skilling.json refers to the right release, but has '"drupal/token_custom":"~1.0@alpha2"' from long ago.
Help appreciated! The module can't be installed with Composer at the moment.
----- Update ARGH!! ----
@Clive is probably right, but I don't know how to fix it. Tried removing the line with the bad Composer version string in Git history with:
git filter-branch -f --tree-filter 'sed -i "/drupal\/token\_custom/d" composer.json' -- --all

Also tried BFG repo rewrite tool to replace the bad string.
Pushed. Created new releases. Cleared composer cache. composer require generates the same errors.
Afraid I don't understand Clive's suggestion to rebase a fix onto the branch containing the invalid version string. How is that done?
Comment: _The file $skilling.json refers to the right release, but has '"drupal/token_custom":"~1.0@alpha2"' from long ago_ It contains all the releases so it makes sense that the string is there...I guess Composer parses all of them each time. I suspect one way to fix it would be to rebase a fix onto the branch containing the invalid version string (looks like that's 1.0.0), then release a new version of the module. At that time the provider file should hopefully be regenerated with the tagged composer.json versions as they exist at that time (i.e. with the fixed version string)
Comment: @Clive is right: The error is caused from the fact the custom code running for the packages.drupal.org domain parses all the project branches, even the ones that could not be used from drupal.org to create a development snapshot.
Comment: Tried various things, listed under ARGH in the editing question. How would I implement the rebasing suggestion?
Answer: Im the maintainer of packages.drupal.org - I went ahead and deleted the invalid data out of the database, and this will install now.
I've also opened and issue on drupal.org to put more defensive measures in place. https://www.drupal.org/project/project_composer/issues/3076342
I think something must have changed in how permissive composer is with certain bad version constraints.
Comment: Thank you, thank you!!!


Naming CDK resources dynamically

Question: I'm using the CDK to create some infrastructure from a yaml template file. Some resources require multiple instances. I thought writing a function would be the easiest way to create multiple instance of the resource
Function
def create_vpn_connection_route(cidr_count, destination_cidr):
    vpn_connection_route = aws_ec2.CfnVPNConnectionRoute(
        self,
        f'vpn_connection_route{cidr_count}',
        vpn_connection_id=vpn_connection.ref,
        destination_cidr_block=destination_cidr
    )
    return vpn_connection_route

I then loop over it and generate the "Id" by enumarating over the destination_cidrs like so
for cidr_count, destination_cidr in enumerate(tenant_config['vpn_config'][0]['destination_cidrs']):
            create_vpn_connection_route(cidr_count, destination_cidr)

This is what's in my yaml
vpn_config:
    - private_ip:
        - 10.1.195.201/32
        - 10.1.80.20/32
        - 10.1.101.8/32

Is there a better way to do this in the CDK? and can I dynamically generate Id'S for resources?
Cheers
Answer: I don't know that it makes your code much better, but you can use a Construct instead of a function.
class VpnConnectionRoute(core.Construct):
    def __init__(self, scope, id_, vpn_connection, destination_cidr):
        super().__init__(scope, id_)

        self.vpn_connection_route = aws_ec2.CfnVPNConnectionRoute(
            self,
            'vpn_connection_route',
            vpn_connection_id=vpn_connection.vpn_id,
            destination_cidr_block=destination_cidr
        )

# ...
for cidr_count, destination_cidr in enumerate(tenant_config['vpn_config'][0]['destination_cidrs']):
  VpnConnectionRoute(self, f"route{cidr_count}", vpn_connection, destination_cidr)
  VpnConnectionRoute(self, f"route{cidr_count}", vpn_connection, destination_cidr)
  VpnConnectionRoute(self, f"route{cidr_count}", vpn_connection, destination_cidr)

CDK will automatically name your resources based on both the construct and your name. So the end result will look like:
    "route1vpnconnectionrouteAE1C11A9": {
      "Type": "AWS::EC2::VPNConnectionRoute",
      "Properties": {
        "DestinationCidrBlock": "10.1.195.201/32",
        "VpnConnectionId": {
          "Ref": "Vpn6F669752"
        }
      },
      "Metadata": {
        "aws:cdk:path": "app/route1/vpn_connection_route"
      }
    },

You can also just put destination_cidr inside your route name. CDK will remove all unsupported characters for you automatically.
for destination_cidr in tenant_config['vpn_config'][0]['destination_cidrs']:
        aws_ec2.CfnVPNConnectionRoute(
            self,
            f'VPN Connection Route for {destination_cidr}',
            vpn_connection_id=vpn_connection.vpn_id,
            destination_cidr_block=destination_cidr
        )

The best solution here probably depends on what you want to happen when these addresses change. For this particular resource type, any change in the name or the values will require a replacement anyway. So keeping the names consistent while the values change might not matter that much.

Naming CDK resources dynamically


jquery object executing object's assigned function

Question: This is a simplified version.
If I do something like this:
var object = [{name:"bob", type:"silly", hair:"brown", func:someFunction},
              {name:"greg", type:"serious", hair:"blonde", func: differentFunction}];

$('#thing').bind("click", object[0], handleTranslator);

function handleTranslator(e){
    $([e.data.func]);
}

function someFunction(){
    console.log("clicking bob should trigger this function");
}

function differentFunction(){
    console.log("clicking greg should trigger this function");
}

When I click #thing, it should trigger someFunction but it doesn't. Not sure why.
Ideally, I'd like to also be able to see (console.log) my object[0] from inside someFunction.
Thanks for the help.
Comment: What does your HTML look like?
Comment: @AlienWebguy This is a simplified example.
Comment: @ExplosionPills #thing is already in the dom
Comment: I'm assuming $([e.data.func]); is what is wrong. Everything else seems fine.
Comment: why are you wrapping functions in `$()` ?
Comment: @charlietfl I was trying different things - didn't know the syntax
Answer: You're not invoking your function:
function handleTranslator(e){
    e.data.func();
}

Demo: http://jsfiddle.net/CEdvt/
Comment: Uncaught TypeError: Property 'func' of object # is not a function
Comment: This works... I tried it originally but I think I had my function in quote like: "differentFunction"  TY


Why isn't math on the sine of angles the same as math on the angles in degrees?

Question: I noticed something just now. This is probably a stupid question, but I'm going to ask it anyway. Because when I discover that my understanding of a topic is fundamentally flawed, I get nervous.

Basically I'm suppose to show that the angle marked in red is $sin \space \alpha = \frac{3}{5}$. Note that this task is on the part of the test without calculator. My first thought was that the whole thing is 90 degrees. And the other to angles I can fine easily. AB is 1 and BE is 0.5. And the length of AE is $\frac{\sqrt 5}{2}$. So I calculate the angle for the bottom triangle.
$sin \space = \frac{BE}{AE} = \frac{\frac{1}{2}}{\frac{\sqrt 5}{2}} = \frac{1}{\sqrt 5}$
I know that sine of 90 is 1, right. Now it all falls apart, the following is wrong.
The angle on the top side of the red angle is equal to the one just calculated. So I did this.
$1 - 2 \times \frac{1}{\sqrt 5}$
And expected to get $\frac{3}{5}$, which I didn't. The following is correct.
$\arcsin(1) - 2 \times \arcsin(\frac{1}{\sqrt 5}) = 36.86$
$\arcsin(\frac{3}{5}) = 36.86$
Why won't the expression without arcsin give me $\frac{3}{5}$ ?
Hope this makes sense, I'll be right here pressing F5 and updating if more info is needed. Thank you for input.
Comment: A similar thing happens with $f(x) = x^2$. We have $f(1) = 1$ but $f(2) = 4 \neq 2 f(1)$. What's with that?
Answer: A $sin$ of an angle is not the same as an angle, it's a function of the angle. You can add angles:
$$\alpha = \alpha_1+\alpha_2$$
But not the $sin$'s:
$$\sin(\alpha) \neq \sin(\alpha_1)+\sin(\alpha_2)$$
In fact, this is true for most functions, and this property is called "non-additivity".
Comment: @nbubis: Not exactly. This is called *additivity*. Linear functions, in addition to being additive, are also homogeneous. A function $f(x+y)=x+25y$, where $y$ is rational and $x$ is from a fixed complement subspace of $\bf Q$ in $\bf R$  (as a space over $\bf Q$) is additive, but *not* linear over reals.
Comment: @nbubis: only if $b=0$, of course!
Comment: @nbubis: It isn't: the function I'm referring to *is* a function over the reals. (It is the same for *measurable* functions over the reals, for example, but not *arbitrary*.)
Comment: @nbubis: A linear function must satisfy both $f(x+y) = f(x) + f(y)$ and $f(cx) = c*f(x)$ *(with `c` a constant)*.  So while it's true that not satisfying the first condition would make the function non-linear, saying *"this property is called non-linearity"* is incorrect, because it's possible for the first condition $f(x+y) = f(x) + f(y)$ to be satisfied but the function to still be non-linear *(by not satisfying the second condition)*.  The name of the first condition is *"additivity"*, so the correct name for your property above would be *"non-additive"*.
Comment: Ok, so function that this does work with. Can they said to "preserve addition"? It's an expression I've heard.
Comment: @Algific - only *linear functions* preserve this property. In 1D, this is true only for function of the form: $f(x) = ax+b$
Comment: @tomasz - You're right of course, but for functions over the reals this is the same.
Comment: @nbubis Take care, it's not true for `f(x)=1` or `f(x)=x+1`, as these are "affine" rather than "linear".
Comment: @haydoni - I'm familiar with the terminology you are using , but in other contexts affine functions are also called linear.
Comment: @nbubis In which case linear does not imply additive, see examples above. :)
Answer: You know that $\alpha+2\beta=90^\circ$. There is no rule that $\sin\alpha+2\sin\beta=1$. In maths it's the single most important thing to stick to given rules and not accidentally "invent" new ones.
For your problem: Maybe writing $\sin\alpha=x/y$ with some auxiliarly lines (e.g. the height on the triangle) and successively derive $x$ and $y$ by a chain of Pythagoras applications.
EDIT: Or better use http://en.wikipedia.org/wiki/Law_of_cosines and derive the sine from cos.
Comment: @Gerenuk: Again, I disagree. You *should* guess "rules", and when you do, you *will* guess wrong often. The thing is, before *applying* a "rule", you should *verify* if it is actually true. If you never guess and invent things, you will never learn anything new.
Comment: @Garenuk: The point is, if you make people afraid of making mistakes and force them to just follow same-old algorithms over and over, you're reducing "mathematics" to mindless rote learning. Which is why many people find mathematics incomprehensible. The best way to learn is to make mistakes and understand *why* they're mistakes, not avoiding mistakes at all costs.
Comment: (+1) for the 'In maths it's the single most important thing to stick to given rules and not accidentally "invent" new ones.'
Comment: @BiditAcharya: I disagree. I think inventing new "rules" is what mathematics is *about*. For example, this exercise can be easily done as soon as you see that $\sin(\alpha)=\cos(\pi/2-\alpha)$ and $\cos(2\beta)=\cos(\beta)^2-\sin(\beta)^2$ which are both "new rules".
Comment: @tomasz: It's about _erroneously inventing_ rules. The main reason for pupils doing so many mistakes in maths is because teachers fail to explain that is no "oh this equations vaguely look like that or that rule", but there is only "it's exactly like" or "it's not applicable". One single incorrect rule in maths is like a virus that spoils all results. So don't guess rules!
Comment: @tomasz, "The thing is, before applying a "rule", you should verify if it is actually true." that is exactly my point. I don't know why you disagree :)
Comment: @tomasz: You like to disagree even if things aren't wrong, huh?! :) Anyway, you might do it right, but if you teach students your way, the average student will fail exams. The option of intuition is poison to the average student.
Comment: @Gerenuk: I primarily disagree with the wording. And mathematics is about mathematics, the art, the reasoning, and yes, the intuition, not passing (or failing) exams. Of course, you must be wary not to trust your intuition too much, since it *is* often misleading. In mathematics as much as anywhere else.
Answer: Let $\angle EAB = \alpha_1$. Then $\sin(\alpha+\alpha_1)=2/\sqrt{5}$.
$\sin(\alpha+\beta)=\sin\alpha\cos\beta+\cos\alpha\sin\beta$
i.e. $\sin\alpha\cos\alpha_1+\cos\alpha\sin\alpha_1=2/\sqrt{5}$
$\cos\alpha_1=2/\sqrt{5}$ and $\sin\alpha_1=1/\sqrt{5}$ (from figure)
Therefore
$$2\sin\alpha+\cos\alpha=2\tag1$$
(Canceling denominator $\sqrt 5$)
If $\sin\alpha=3/5$ then $\cos\alpha=4/5$, i.e.
$$2\sin\alpha+\cos\alpha=2\frac{3}{5}+\frac{4}{5}=2\tag2$$
Eq. $(1)$ = Eq. $(2)$
Hence proved...
Also $\sin(\alpha+\beta)\ne\sin\alpha+\sin\beta$.
(Which is called non-linearity, probably the answer to the question is this)


Binary Classifier with training data for one label only

Question: In some real-life problems such as authentication, we only have training data for one label (x is authenticated) while the other label doesn't have any data or only few entries (x is an imposter).
What kind of changes should we do in order to adjust a classifier to deal with a label targeted for other/unknown entries?
Comment: Just to clarify, you're saying that you have a lot of missing *labels*, correct?  You still have predictor variables for the unknown entries?
Comment: Only one missing label. A binary classifier with 1=authorized as John Doe, -1= Imposter of John Doe. I only have the training data made by John Doe, so all the training points that I have are f(x)=1.
Comment: Take the example of Speaker Recognition. I only train it on my voice to authorize me, but I don't have any data for imposters that try to pretend to be me.
Answer: This is actually a widespread situation, for example in industrial quality control, you want to decide whether a batch of product is fit for sale. Also medical diagnosis (if it isn't a differential diagnosis) often faces the same problem.
So-called one-class or unary classifiers address this. The idea is to model the "in" class independently of possible other classes.
In chemometrics, SIMCA is a popular approach to this. Basically, you compress your class into a PCA models and then develop a boundary outside which you deem it sufficiently improbable that the case belongs to that class. (For multiple independent classes, you do this for each class separtely.)
D.M. Tax: One-class classification -- Concept-learning in the absence of counter-examples, Technische Universiteit Delft, 2001 develops a one-class SVM.
Comment: That is exactly what I was looking for. Thanks a lot
Answer: If I understood you correctly, you have many data for class A (auth.) and almost any for class B (imposter) in your (randomly chosen?) training set?
From Wikipedia (Pseudocount),

In any observed data set or sample there is the possibility, especially with low-probability events and/or small data sets, of a possible event not occurring. Its observed frequency is therefore zero, apparently implying a probability of zero. This is an oversimplification, which is inaccurate and often unhelpful, particularly in probability-based machine learning techniques such as artificial neural networks and hidden Markov models. By artificially adjusting the probability of rare (but not impossible) events so those probabilities are not exactly zero, we avoid the zero-frequency problem. Also see Cromwell's rule.

So I would therefore artificially include some data for the other, very rare label/class.
Comment: I added some comments to clear the question (sorry for ambiguity) but you've understood me correctly. So do I need to add noise or random adjustments for the authorized training data to generate imposters data? Am I correct?
Comment: So you don't have ANY data for the imposters? Not even in your whole population (because usually, training data is a random sample from the population)? I don't know what to do in that case, then maybe I misunderstood the question.
Comment: Yes, I don't have any data for imposters. The training data that I have only contain some metrics to authorize different users.
Comment: Maybe you should post some example data so people can fully understand what you're trying to achieve.


Why did Lou Reed make Metal Machine Music?

Question: For background, it's a record that was made "without musical instruments" by rigging up ring-modulators and envelope filters and tone generators to create a sort of living shape of feedback.
But every moment sounds exactly the same. I've listened to the whole darned thing. It's the closest thing I've ever found to "pure" noise. In that capacity, I have found use for this record in noise battles with the neighbors. But surely, it's supposed to be some kind of "Dada" statement about the definitional nature of categories, right? It's not supposed to be ammunition.
Certain of Prokofiev's Visions Fugitives elude tonality but retain idioms of phrasing. And even the most heavily-distorted Rock retains the "pulse" of organic rhythm. Nine Inch Nail's The Downward Spiral incorporated "textures" of noise, but with both pulse and phrasing.
So, was there a musical intent behind the creation of the recording or was it entirely record-company politics? Could such an arrangement of technology be used to produce "interesting" sounds?
Answer: It is my understanding that at least part of the intent of this piece of music is "I want out of my contract with RCA".
Answer: Years before Lou Reed released Metal Machine Music during his solo career, he played in a bad called The Velvet Underground with violist John Cale.  John Cale is a classically trained musician, who studied with Humphrey Searle (a student of Anton Webern of the second Viennese school).  During his early life and classical training he created relationships with many modern artists (Xenakis, Koussevitzky, etc.) as well as composing original conceptual music in the same vein as John Cage and Fluxus.
During this period he became very interested in Minimalism.  Reed met up with John Cale, Tony Conrad, and Walter de Maria via Pickwick records, whom he was working for at the time.  This band collaborated with many modernist groups and artist, including Andy Warhol who utilized them in a multimedia event called the Exploding Plastic Inevitable.
Lou Reed was the principal songwriter for the group and was very interested in alternate tunings (one of which tuned all of the strings to the same note in order just to create a drone.)  With Lou Reed's interest in alternate tunings, as well as his immersion into modernist music with the members of The Velvet Underground, I think that it is very probable that Metal Machine Music is simply a very interesting exercise in Minimalism (conceptually like Terry Riley's In C, just without any specific tonal structure.)
Answer: You might not think it resembles music - many folks would say the same about opera, or metal, or pop or (insert genre here)...
Lou Reed was making a statement.
People listen to it.
Not sure there is a real question, to be honest - I would just treat it like any other music that I don't 'get'
Comment: Oh come on. "[Music](https://en.wikipedia.org/wiki/Music)" might be loosely defined, but it can definitely be characterised by various qualities, like rhythm, melody, tonality, texture, dynamics, and intent. If you says that white noise is music, then the term is so broadly defined as to include all sounds, and is therefore redundant and pointless. Besides, the question wasn't "is this music?", it was "what's the intent of this piece of music?"
Comment: The definition of music I most commonly see is "organized sound" which is quite loose; but this is necessary so as not to prejudicially exclude any not-yet-recognized organizing principle.


How to use JavaScript to count occurence of a word in entire HTML webpage versus just in an array?

Question: I have a JSON report that I append to my webpage that monitors a server's processes and every processes that is running it returns the string "runn1ng".
I want to do a summary at the top of the webpage that says:
___ out of 10 processes are running.

The ___ number will be the dynamic number that is counted by JavaScript to see how many "runn1ng" appear on the webpage.
I have seen some documentation on here on how to count occurrences of a string within an array, but I am curious if there is a way to count the string occurrence on the entire webpage.
Comment: why not get that data from the JSON instead of the DOM?
Comment: How about assign them to div with unique class, then aggregate a string from the content selection of that class?
Answer: Something like this should work:
var documentHtml = document.documentElement.outerHTML; // Gets page's HTML
var occurences = (documentHtml.match(/runn1ng/g) || []).length; // Searches the page for occurrences

However, as others have mentioned, it's most likely a better and more maintainable solution to have the JSON expose the number of running processes.
How to count string occurrence in string?
How to get the entire document HTML as a string?
Answer: Try this -
var html = document.documentElement.innerHTML;
var n = html.search("runn1ng");


Using PHP ImageMagick with ImageCache Custom actions - Returning image

Question: I'm trying to composite some images using ImageMagick - I know imagemagick via PHP, i'm trying to return the image via PHP but it seems to overwrite the original source file - not ideal as it can apply the filter over and over.
Ideally, I'd like to write the original file with _thumb after it, then call this file via Drupal for display, where it would copy to the appropriate imagecache directory and display from there. Anyone with ImageMagick experience, would be appreciated if you can help.
<code>$location = $image->source;

$newImage = new Imagick($_SERVER['DOCUMENT_ROOT'].'/'.$image->source);

$distort = array( 0.0, 0.0, 0.16, 1.0  );
$newImage->distortImage( Imagick::DISTORTION_BARREL, $distort, TRUE );
$newImage->resizeImage(1600, 1600, Imagick::FILTER_CATROM, 1);
$newImage->cropImage(1500, 1500,60, 50);

$extension_pos = strrpos($fileName, '.'); // find position of the last dot, so where the extension starts
$thumb = substr($fileName, 0, $extension_pos) . '_thumb' . substr($fileName, $extension_pos);
$newImage->writeImage($thumb);

return $thumb;
</code>
Comment: Where does this code live?
Comment: In the 'Custom Actions' for imagecache preset
Answer: Someone might find this useful as Documentation is very sparse for this (this took me over a day to figure out). The problem was I was writing to a seperate file - Works, but ImageCache will delete it, also defeats the point of using ImageCache.
The solution is as follows, to use $image->ops[] and ImageMagick CMD's. (This is entered in the custom actions of imagecache. Distort image, apply mask, and apply overlay. This is used for creating product images for a Shop with just normal images supplied. I'll probably make a blog post in more depth at some point.
<code>$image->ops[] = "-distort Barrel '0.0 0.0 0.16 1.0'";
$image->ops[] = "-resize 1600x1600";
$image->ops[] = "-crop 1500x1500+60+50";
$image->ops[] = "'sites/default/files/coushin-bg.png' -compose Dst_In  -gravity center -alpha Set -composite -format png -quality 90 ";
$image->ops[] = "'sites/default/files/Blank-Cushion.png' -compose Multiply  -composite -format png -quality 90 ";
return $image;
</code>


Difference between unsymmetric and anti-symmetric relations?

Question: I am finding difficulty in understanding the difference between asymmetric (non-symmetric) and anti-symmetric relations. Though I didn't quite find any mention of the word asymmetric in the reference book, our teacher had mentioned it while explaining the concepts.
So my question, are non-symmetric and anti-symmetric relations, both the same thing or different? It would be appreciated if someone could explain using a couple of examples. (I did not understand the definition, so I did not approach the sums, hence this is a general question.)
Answer: A symmetric relation is one where the order can be flipped. Equality is symmetric because if $x=y,$ then $y=x$ also. Weak inequality $\leq$ is also symmetric. Strict inequality $<$ is not symmetric.
An antisymmetric relation is one where distinct elements cannot be reversed. Weak inequality is antisymmetric.
An asymmetric relation is one where the equation never holds. Asymmetric means antisymmetric and irreflexive. Strict inequality is asymmetric.
Comment: How is weak inequality symmetric?
Answer: Denote $R$ the relation.
Non-symmetric is just $\:\lnot(aRb\implies bRa)$, whereas anti-symmetric is $(aRb)\wedge(bRa)\implies a=b$.
Comment: @Rick: Yes, I intentionally didn't add them to make a more intuitive sketch. I don't think the O.P.'s difficulties are at that level. But maybe I'm wrong.
Comment: You've left behind the quantifiers, and yes it does matter; $\neg (\forall a,b (aRb \to bRa))$ is not the same as $\neg (\exists a,b (aRb \to bRa))$ and also   $\neg (\forall a,b (aRb \to bRa))$ is not the same as $\forall a, b (\neg(aRb \to bRa))$.
Comment: @Bernard Yes, you are right. The difficulty level is not too high, just the beginners.
Comment: @Rick Though it is not mentioned in our book, I am quite intrigued in knowing the difference between your second statement.  ¬(∀,(→)) is not the same as ∀,(¬(→)). I know that "for all" is very much different than "there exists", but the second statement is quite new to me.
Comment: Should I post a new question in accordance to this, or will it be okay if you edit your answer here?
Comment: It is the same as $\;\exists a\exists b\bigl(\lnot(aRb \to bRa)\bigr)$. If can be further simplified, as $p\to q$ is $(\lnot p)\vee q$. So it finally becomes $\;\exists a\exists b\bigl( (aRb)\wedge(\lnot(bRa))\bigr)$.
Answer: The definitions are as follows:

A relation $R$ on a set $X$ is symmetric if for all $a, b \in X$, $aRb$ implies $bRa$.
A relation $R$ on a set $X$ is non-symmetric if it is not symmetric; i.e. there exist $a, b \in X$ such that $aRb$ does not imply $bRa$.
A relation $R$ on a set $X$ is called antisymmetric if for all $a, b \in X$, $aRb$ and $bRa$ implies $a = b$.

One can see that non-symmetric and antisymmetric relations are quite different through easy examples. One stock of examples for antisymmetric relations is given by directed graphs; take $X = \{1,2,3,4\}$ to be the set of vertices of graph and define the relation $R_1$ on $X$ as follows: $$a R_1 b \iff \text{there is a directed edge from } a \text{ to }b.$$ A concrete example witnessing non-symmetricity for $R_1$ would be the following graph: $$\require{AMScd}\begin{CD}
1 @>>> 2\\
@VVV @VVV\\
3 @>>> 4
\end{CD}$$ Then $R_1$ is non-symmetric, since $2 \to 4$ (i.e. $2R_14$) but $4 \not\to 2$ (i.e. it is not the case that $4 R_1 2$).
Finally, for antisymmetric relations you can take any partial order on a set, such that the standard $\leq$ relation on the integers or the reals, say.


Slideshow with touchscreen support

Question: I'm creating a website and I would to add a slideshow that works also with touchscreen on smartphones and tablets.
Could you suggest me some modules that do it?
Answer: Ok, I've found this: Flex Slider, this seems works on my android smartphone

Slideshow with touchscreen support


DateTime.Now gives me only date when I set it as object in database

Question: I am using @DateTime.now in my view to save current date but somehow I can't set current date AND hour to my object, it does not saves hours/minutes/seconds. It saves same data as @DateTime.Today whould show. It just saves as

2014-01-06 00:00:00

While date is current(correct) date and hour is set to zeroes.
Here is my model, not much to see, I don't see how it could be possibly wrong here.
public class Posts
    {
        ...
        public DateTime PostDate { get; set; }
        ...

    }

And here is how I put DateTime to my model in view:
@using (Html.BeginForm()) {
    @Html.AntiForgeryToken()
    @Html.ValidationSummary(true)

    <fieldset>

        [...]

        <input type="hidden" name="PostDate" firstname.lastname@example.com/>

            <input type="submit" value="Create"/>

    </fieldset>
}

When I call @DateTime.Now in view it shows me correct values.
I tried to convert it to string (By making object PostDate also string) but I was still getting the same issue.
What I am missing?
Comment: Looks like your column type is `Date` instead of `DateTime`.
Comment: what is your column's data type in your database ?
Comment: Please show us the **rendered** HTML.
Answer: Probably acting weird because you didn't put quotes around your value attribute. Change to this.
<input type="hidden" name="PostDate" value="@DateTime.Now" />

as @JohnH suggests this works too
@Html.Hidden("PostDate",DateTime.Now)

Comment: Good spot.  That might be it, too.  Although, rather than just adding quotes, I'd suggest using `Html.HiddenFor` / `Html.Hidden` instead, as they'll generate the correct output without the fuss.
Answer: When I encountered this problem, I realized it was because in the SQL, I had chosen "date" instead of "datetime" in the design of my table.  The database could not accept the time value because it was misconfigured.  Changing the table definition to accommodate the full "datetime."


Show ellipsis in Tailwind CSS truncate

Question: I am using the truncate property in Tailwind on a p tag, but it doesn't show the ellipsis after truncation. It only hides the overflow. Any idea how to show the 3 dots when it's truncated?

{textName}

{descriptionName}

Comment: SOLVED. i had to use display:block instead of flex for my container
Comment: Have you tried adding `overflow-hidden` to your container div?
Answer: className is wrong attribute for HTML tags. You must use like this:

{textName}

{descriptionName}

Comment: i am writing in react

Show ellipsis in Tailwind CSS truncate


Bootstrap 4 Grid Layout with Form

Question: I am making simple form and control side by side with full width control but it is not working and if I put col-sm-xx than it will break and to another line. So how can I make them in one line with full column width

                        <button type="button" class="btn btn-primary dropdown-toggle" data-toggle="dropdown">
                            Location
                        </button>

                            Sharq
                            Shuwaikh
                            Hawally
                            Farwaniya
                            Hawally

                    <input type="text" placeholder="Mobile" class="form-control" id="txMobile" minlength="8" maxlength="8" pattern="\d*">

Comment: @AG_BOSS let me try and get back to you
Comment: @AG_BOSS Check my updated image
Comment: @AG_BOSS There is no `col-xs` in Bootstrap 4. It's just `col`. See: https://getbootstrap.com/docs/4.1/layout/grid/#grid-options
Comment: ok understood @Klooven
Comment: @AG_BOSS margin-right is also not good idea as it will give different output in different mobile
Comment: where did i tell @Milind ?
Comment: @AG_BOSS .items{
  margin-right: 10px;
}
Comment: my other post (Pradeep)? is it that one?
Comment: i have edited that
Answer: You should use col-auto to minimize the width of the dropdown button and icon, and then col to make the input fill width...
https://www.codeply.com/go/hJcCGGUnpC

                <button type="button" class="btn btn-primary dropdown-toggle" data-toggle="dropdown">
                    Location
                </button>

                    Sharq
                    Shuwaikh
                    Hawally
                    Farwaniya
                    Hawally

            <input type="text" placeholder="Mobile" class="form-control" id="txMobile" minlength="8" maxlength="8" pattern="\d*">

Comment: Use the [spacing utils for padding](http://getbootstrap.com/docs/4.1/utilities/spacing/). For example, `px-1`.  This is outside the scope of the original question which was how to keep the form inline. Please update the question with the spacing requirements.
Comment: Your reply is okay but there is not space between the elements. I want some space between them
Comment: Just remove `no-gutters` from the `.row`. I thought you wanted no space.
Comment: ok removing gutters works but can we reduce white space now it have lot of space :(
Answer: Try the following snippet

.items{
  margin-right: 10px;
}
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css" integrity="sha384-Gn5384xqQ1aoWXA+058RXPxPg6fy4IWvTNh0E263XmFcJlSAwiGgFAW/dAiS6JXm" crossorigin="anonymous">

        <button type="button" class="btn btn-primary dropdown-toggle" data-toggle="dropdown">
                            Location
                        </button>

          Sharq
          Shuwaikh
          Hawally
          Farwaniya
          Hawally

      <input type="text" placeholder="Mobile" class="form-control" id="txMobile" minlength="8" maxlength="8" pattern="\d*">

Comment: The difference is i think in div class="col" right?
Comment: what are the other dependencies your having @Milind
AG_BOSS yes seems to be. because it works in this snippet though
Comment: Sorry it is working but they don't have space between each other how can we do that
Comment: can you show a screenshot, im not clear what you meant @Milind
Comment: maybe add some margin between then by declaring a class for css?
Comment: Check now. I have updated the answer by adding a margin-right to the button by creating a css class called items and referring it in the button @Milind

Bootstrap 4 Grid Layout with Form


Posso usar isNaN() para verificar se uma string contém somente dígitos de 0 a 9?

Question: Estou lendo o livro "Programação JavaScript da série Use a Cabeça!" e não estou conseguindo localizar um erro que o livro pede para identificarmos, segue o desafio:

Pegue um número de telefone na forma "123-4567" e escreva um código para aceitá-lo ou rejeitá-lo. Para ser aceito o número deve ter sete dígitos, 0 até 9, com um traço no meio.
function validate(phoneNumber) {
    if (phoneNumber.length !== 8) {
        return false;
    }

    var first = phoneNumber.substring(0,3);
    var second = phoneNumber.substring(4);

    if (phoneNumber.charAt(3) !== "-" || isNaN(first) || isNaN(second)) {
        return false;
    }
    return true;
};

Você consegue imaginar algum bug que o programador tenha introduzido com o seu uso de isNaN()?

Fiz diversos testes aqui, mas o código parece funcionar corretamente quando insiro um número no formato especificado, não consegui encontrar o bug.
Comment: Relacionada ou dup: [Por que isNaN(null) retorna "false"?](https://pt.stackoverflow.com/questions/484999/por-que-isnannull-retorna-false?rq=1)
Comment: `isNaN('1e2')`, por exemplo, retornará `false`, mesmo não sendo um número válido para telefone. O `e` é utilizado para notações científicas, mas não lembro bem o suficiente para poder explicar isso melhor.
Answer: O problema é que a função retorna true para vários casos em que deveria retornar false (ou seja, dá falsos positivos: diz que um telefone inválido é válido). Exemplos:

function validate(phoneNumber) {
    if (phoneNumber.length !== 8) {
        return false;
    }
    var first = phoneNumber.substring(0, 3);
    var second = phoneNumber.substring(4);
    if (phoneNumber.charAt(3) !== "-" || isNaN(first) || isNaN(second)) {
        return false;
    }
    return true;
}

for (var tel of ['-12-3e10', '   -    ', '0.2-   3', '+00--0.3'])
    console.log(`${tel}=${validate(tel)}`);

Repare que todas as strings acima ('-12-3e10', '   -    ', '0.2-   3' e '+00--0.3') são consideradas telefones válidos, e a saída do código é:
-12-3e10=true
   -    =true
0.2-   3=true
+00--0.3=true

Isso acontece porque segundo a especificação da linguagem, isNaN usa este algoritmo para converter seu argumento para número.
No caso específico de strings, é usada a operação StringToNumber, que por sua vez usa este algoritmo para obter o valor numérico que a string representa. E este algoritmo não funciona somente com dígitos de 0 a 9, pois há várias outras strings que podem ser convertidas para número.
Claro que strings como '123' são corretamente identificadas como válidas. Mas o mesmo acontece com '-12' (que representa o número negativo -12), ou '3e10' (número em notação científica, que representa 3 x 1010, ou seja, 30000000000 - 30 bilhões), ou ainda '0.2' (número com casas decimais), '+00'  (zero), '-0.3' (número negativo e com casas decimais), etc.
Talvez o caso com espaços seja o mais estranho, mas é porque uma string que só contém espaços é convertida para o número zero, e portanto isNaN retorna false para este caso, conforme citado na documentação. E no caso do    3, também é considerado um número válido porque os espaços do início e fim da string são ignorados.
Ou seja, usar isNaN para verificar se uma string só contém caracteres que correspondem aos dígitos de 0 a 9 está errado, porque esta função considera vários outros casos que possuem caracteres diferentes. Sendo assim, ela não é adequada para este problema, pois apesar de funcionar com telefones válidos, ela não funciona para vários casos inválidos (dizendo erroneamente que são válidos).

Portanto, uma forma de resolver é verificar explicitamente se os caracteres são dígitos de 0 a 9:

function validate(phoneNumber) {
    if (phoneNumber.length !== 8) {
        return false;
    }
    for (var i = 0; i < phoneNumber.length; i++) {
        if (i === 3) { // posição que deve ter hífen
            if (phoneNumber[i] !== '-') {
                return false;
            }
        } else { // posição deve ter dígito de 0 a 9
            if (phoneNumber[i] < '0' || phoneNumber[i] > '9') {
                return false;
            }
        }
    }
    return true;
}

for (var tel of ['-12-3e10', '   -    ', '0.2-   3', '+00--0.3', '123-4567', '000-9999'])
    console.log(`${tel}=${validate(tel)}`);

Ou seja, para a posição que deve ter o hífen, eu verifico se tem esse caractere. Para todas as outras posições, verifico se o caractere corresponde a um dígito de 0 a 9.
Agora ela retorna false para os quatro primeiros (que de fato são inválidos), e true para os dois seguintes (que são válidos).

E claro, provavelmente alguém vai sugerir pra usar regex:

function validate(phoneNumber) {
    return /^\d{3}-\d{4}$/.test(phoneNumber);
}

for (var tel of ['-12-3e10', '   -    ', '0.2-   3', '+00--0.3', '123-4567', '000-9999'])
    console.log(`${tel}=${validate(tel)}`);

No caso, os marcadores ^ e $ indicam o início e fim da string, assim garanto que ela só vai ter o que está na regex (nem um caractere a mais, nem a menos). Depois o atalho \d pega um dígito de 0 a 9, e o quantificador {n} indica a quantidade (ou seja, primeiro tem 3 dígitos, e depois do hífen tem 4).
Apesar de ser mais curto, regex em geral é mais lento (e muitas vezes mais difícil de entender e manter).
Comment: No fundo, a lição que fica é: não teste apenas com os casos válidos, tem que testar com os inválidos também :-)
Comment: dica de ouro dos testes :D
Comment: Da pra evitar vários dos problemas do isNaN utilizando Number.isNaN: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number/isNaN


How to schedule an action to reliably be performed once every 5 minutes?

Question: I have a need for a function to run every N minutes (it doesn't need to be EXACTLY every N minutes, but it should still occur within a reasonable amount of time, maybe N+/- 5 minutes)
I've been bouncing around between the DrupalQueue class, job_scheduler, rules, actions, etc., and each time it seems like I run into a wall.
My current set up is that I use job_scheduler_trigger. I seem to have it setup correctly (using a basic UI created action of "Send email"), and I have it set to go every 5 minutes, but it NEVER fires. The "Next" run time just keeps incrementing itself properly,  but the "Last" run time is always "Never". I have no idea what I'm doing wrong, or even if this is the best way to go about it.
Comment: What kind of function is it? If it can be done through code, then you can just create a PHP file which bootstraps Drupal and performs your tasks. This then can be called from a crontab (sudo crontab -e) to run every 5 minutes :) That's provided you have shell access to your server
Comment: How do you fire your cron? Without it firing at least every 5 minutes, no Drupal system will be able to fire anything every 5 minutes. I hope you knew that already, but your question doesn't show it.
Comment: Correction: you don't need to fire cron if your solution provides something for you to fire instead, but you do need to fire *something* from the outside.
Comment: Another option is using drush and creating a custom task and then using crontab on your system.
Comment: I ended up scaling it back a bit (at least as far as the number of involved modules went.) I added a Drush command to my already-in-development module, then altered the crontab for the apache user to fire the command every 5 minutes.
Answer: Using Rules and Rules scheduler (submodule of Rules) seems to me "a" valid approach.
What you actually need to do is a minor variation of what is explained in the tutorial Hourly tasks using rules scheduler: in your case you should use an offset of 5 minutes (instead of only after 1 hour). And you need to run cron every 5 minutes also (not hourly as in that tutorial).
And as explained also in that tutorial: Initially execute the component manually (from then on every other 5 minutes the rule will be executed again).
Note: How to schedule a regular job using Rules in Drupal 7 is another tutorial that covers this topic.
Comment: This seems valid, but I went with a different approach.


Is it correct to report result like this?

Question: I often encounter (what I think is) incorrect reporting of confidence as 'probability'. This is possibly the single most common source of confusion regarding frequentist significance testing that a population statistic is seen as a random variable, not an unknown parameter.
However, I stumbled upon this passage from a very important and respectable source (https://climate.nasa.gov/evidence/):

The current warming trend is of particular significance because most
  of it is extremely likely (greater than 95 percent probability) to be
  the result of human activity since the mid-20th century and proceeding
  at a rate that is unprecedented over decades to millennia (1).

In the linked article, there are effect estimates that fall into 95% CIs and this is where (in my opinion) the above claim comes from. So, 95% of such constructed intervals would contain the true effect.
This got me thinking, whether I'm not overly strict about not mixing confidence and probability. When communicating the result to the general public, it seems to be common to speak in terms of likelihood, because people tend to think they have good grasp of it. Even if the studies show it is extremely subjective.
But my question is: do you think this simplification is justified? Or do I misunderstand the report they are linking to?

Update:
Assuming that the statement is indeed based on hypothesis testing, I would say that it is an example of a 'statistical colloquialism'. So to rephrase my question: as there is not one universal definition of probability, do you think it is acceptable to present the findings like this to the general public -- who has some intuitive understanding of the likelihood, based on the experience -- even if it not mathematically correct?
Comment: It could be an innocent mistake, it could also refer to some estimate obtained not from hypothesis testing.
Comment: @user2974951 Sure, I think my question can be rephrased: how innocent is this mistake or whether I incorrectly assume that this comes from hypothesis testing :)
Answer: The most formal way to state it is:
"Repeating the experiment an infinite number of times, and constructing the 95% CI in exactly the same way, the true population parameter lies inside the CI 95% of the time"
A common shorthand (and in my opinion correct) is:
"The true parameter lies inside the CI with 95% certainty/a probability of 95%"
with the understanding that the CI is random, not the population parameter.
Comment: Your first definition is the one I agree with (I included a shortened version of it in my question). I understand your reasoning why the shorthand is correct. However, this would only work if we approached infinite number of experiments, while we have just one experiment. To put it differently, it would mean that Bayesian credible intervals are the same as confidence intervals. I don't want to split hairs, but I seek a good way of communicating this. For me, 95% confidence was just that: not 100% confidence, but close to it. I don't try to express it as a probability.
Comment: I found this answer that contains an example showing why "The true parameter lies inside the CI with 95% certainty/a probability of 95%" is not correct: https://stats.stackexchange.com/a/26457/11115. I updated the question to reflect my current understanding of the issue.


Binomial expansion lower bound $A^n + B^n \le (A+B)^n$ for non-integer $n$

Question: By the Binomial expansion for integer powers,
$$ (A+B)^n = \sum_{k=0}^n {n\choose{k}} A^{n-k} B^{k}$$
(I'm assuming $A,B\ge 0$) and so we get the easy estimate $A^n + B^n \le (A+B)^n$ for any positive integer $n$.
Now what happens when we take $n$ to be non-integer? Well if $0<n\le1$, then we have the reverse inequality,
 $$(A+B)^n \le A^n + B^n ,\qquad {(0<n\le 1)} $$
What about if $n>1$ is a non-integer? Can we still say $A^n + B^n \le (A+B)^n$? I'm pretty sure the answer is yes, but I wanted to check with you guys. Here is my quick argument.  Let $n = p + \alpha$ where $p \in \mathbb{N}$ and $0<\alpha<1$.
\begin{align} A^n+B^n &= A^\alpha A^p + B^\alpha B^p \\ &\le \text{max}(A^\alpha,B^\alpha) (A^p+B^p) \\ &\le \text{max}(A^\alpha,B^\alpha) (A+B)^p \\ &\le (A+B)^\alpha (A+B)^p \\ &= (A+B)^n\end{align}
Comment: This is a correct proof.
Answer: Alt. hint: $\;\displaystyle \left(\frac{A}{A+B}\right)^n + \left(\frac{B}{A+B}\right)^n \le \frac{A}{A+B}+\frac{B}{A+B}=1\,$ when $\,n \ge 1\,$.
Answer: If $A=B$,
$A^n + B^n \le (A+B)^n$
is
$2A^n \le (2A)^n
=2^nA^n$
or
$2 \le 2^n$\which is true since
$n \gt 1$.
Assuming
$A \lt B$,
dividing by
$B^n$
and letting
$A/B = x$,
$A^n + B^n \le (A+B)^n$
becomes
$1+x^n \le (1+x)^n$
with
$0 < x < 1$.
Let
$f(x)
= (1+x)^n-1-x^n$.
$f(0) = 0$.
$f'(x)
=n(1+x)^{n-1}-nx^{n-1}
=n((1+x)^{n-1}-x^{n-1})
\gt 0$
since
$n-1 > 0$
so
$(1+x)^{n-1}
\gt x^{n-1}$.
Therefore
$f(x) > 0$
for $x > 0$.


Twelve Fold Way Method of Counting

Question: 25 students audition for 10 parts in a play. How many possible casts?
From having done multiple counting problems of this sort, I understand that the solution to this problem is 25!/(25-10)!.
For anyone that is familiar with the twelvefold way: http://en.wikipedia.org/wiki/Twelvefold_way
What should be identified as the balls (students or parts), and what should be the boxes (students or parts), and why? What is the intuitive reasoning for the assignment of balls and boxes?
Thank you
Answer: In the notation used in the The Twelvefold Way, $N$ is the set of balls, here the $10$ different parts. The set $X$ of boxes is the $25$ students. We are counting the number of injective functions from $N$ to $X$.  For every part has to be assigned to a student, with distinct parts assigned to distinct students, hence the injectivity condition.
Comment: How do you know to assign the parts as balls and students as boxes? This is where I get confused.
Comment: If we try to have the students as the set of balls, with the parts as boxes, we would need to consider bijections from a **subset** of the set of balls onto the set of boxes. Counting these is not part of the *Twelvefold Way* classification.
Comment: so in order to use the Twelvefold Way, if only one ball can go into one box, the number of balls must be less than or equal to the number of boxes, correct?
Comment: I have checked the Wikipedia article. Your permutation problem is the first one listed in the discussion of classical combinatorial problems.
Comment: Certainly the set of balls can be bigger than the set of boxes *in general*, but if the functions have to be injective, then $X$ must be no smaller than $N$.

Twelve Fold Way Method of Counting


Contador não atualiza dados na pagina usando ReactJS e useState(), somente quando coloco um console.log() que consigo ver o resultado

Question: estou fazendo um curso de ReactJs, e estou tentando seguir todos os exemplos de código, porém meu código esta igual ao do instrutor e mesmo assim meu não esta funcionando igual o dele. Toda vez que for clicado em incrementar chama-se uma função para que realize uma conta básica e usa o useState para atualizar o valor do array, mas mesmo assim na minha tela no navegador ao clicar no button continua sem atualizar e se eu colocar um console.log() eu consigo ver que a cada click no button o valor soma mais 1.
import React, {useState} from 'react'
import Header from './Header'

function App() {
  const [count, setCounter] = useState(0)

  function increment() {
    setCounter(count + 1);
    console.log(count)
  }

  return (

       Contador: {count}
       <button onClick={increment}>Incrementar</button>

  )
}

export default App

Comment: Podes mostrar o teu ``? O teu código funciona para mim... https://jsfiddle.net/j81Le92q/
Comment: tenta colocar o  "event.preventDefault ()" na primeira linha da função increment, alias, coloca o event na declaração da função tb function increment(event)
Comment: testei aqui e funcionou.
Answer: Não temos a certeza absoluta, mas, pelo seu problema apresentado faltou pegar children da sua props no componente , para renderizar qualquer funcionalidade sendo essas funções javascript, textos e objetos. Um exemplo que soluciona o problema de não apresentação do valor é a seguinte:

function Header(props) {
  return (

{props.children}
 // children
  )
}
function App() {
  const [count, setCounter] = React.useState(0);

  function increment() {
    setCounter(count + 1);
  }

  return (

       Contador: {count}
       <button onClick={increment}>Incrementar</button>

  )
}

ReactDOM.render(<App/> , document.getElementById('root'));
<link href="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/4.3.1/css/bootstrap.min.css" rel="stylesheet"/>

Aguarde ...

Referencias:

React avançado — Utilizando "props.children" como função de primeira classe
React This Props Children
A quick intro to React's props.children


Discord.py button persistency confusion

Question: I'm looking to make my buttons on an information post persistent so that they remain interactable even after my bot is restarted but I'm not entirely sure how it would work and how it would apply to my code. I am currently using cogs for my discord bot. I have researched about persistency and even checked the example but was struggling to implement it into my code
main.py
import discord
from discord.ext import commands
from discord import app_commands
import asyncio
from variables import cogs, success, failed, check_is_it_us, MY_GUILD, TOKEN, status

bot = commands.Bot(command_prefix=">", intents=discord.Intents.all())

@bot.event
async def on_ready():
    synced = await bot.tree.sync()
    print(f"Logged in as {bot.user} (ID: {bot.user.id})")
    print(f"Loaded {success}") if failed == [] else print(f"Loaded {success}\nFailed to load {failed}")
    print(f"Synced {len(synced)} commands.")
    await bot.change_presence(activity = discord.Game(name=status))

@bot.tree.command(name="sync")
@app_commands.check(check_is_it_us)
async def sync(interaction: discord.Interaction):
    bot.tree.copy_global_to(guild=MY_GUILD)
    synced = await bot.tree.sync()
    print(f"Synced {len(synced)} commands.")
    await interaction.response.send_message(f"Synced {len(synced)} commands.", ephemeral=True)

async def loadCogs():
    for cog in cogs:
        try:
            await bot.load_extension(f"Cogs.{cog}")
            success.append(cog)
        except Exception as e:
            print(e)
            failed.append(cog)

async def main():
    await loadCogs()

asyncio.run(main())
bot.run(TOKEN)

The cog that I would like to have persistent buttons in is called info.py and the command is called /sendinfo and basically I just want the bot to send a message where the user can click on the buttons to see an ephemeral message of the rules and be able to get the Member role.
info.py
import discord
from discord.ext import commands
from discord import app_commands
from typing import Literal
import platform
from variables import suggestionChannel, pollChannel, pollRole, timeformat, stats, convertTime, check_is_it_us, rules
import asyncio
import random
from discord.utils import get

class info(commands.Cog):
    def __init__(self, bot):
        self.bot = bot

    createGroup = app_commands.Group(name="create", description="Allows you to create suggestions and polls")
    infoGroup = app_commands.Group(name="info", description="Shows you info")

    @app_commands.command(name="sendinfo", description="Sends the information message")
    @app_commands.check(check_is_it_us)
    async def sendinfo(self, interaction:discord.Interaction):
        view=discord.ui.View(timeout=None)

        async def rulesButtoncallback(interaction:discord.Interaction):
            rulesEmbed = discord.Embed(title="Official Rules for DRags Club", description="Please agree to our guidelines.")
            for item in rules:
                rule = item.split("|")
                rulesEmbed.add_field(name=rule[0], value=rule[1], inline=False)
            await interaction.response.send_message(embed=rulesEmbed, ephemeral=True)

        rulesButton = discord.ui.Button(style = discord.ButtonStyle.blurple, label = "Rules")
        rulesButton.callback = rulesButtoncallback

        view.add_item(rulesButton)
        async def verifyButtoncallback(interaction:discord.Interaction):
            role = get(interaction.guild.roles, name = "Member")
            await interaction.user.add_roles(role)
            await interaction.response.send_message("You have been verified!", ephemeral=True)

        verifyButton = discord.ui.Button(style = discord.ButtonStyle.blurple, label = "Verify")
        verifyButton.callback = verifyButtoncallback
        view.add_item(verifyButton)
        embed=discord.Embed(colour= 000, title = "DRags' Club", description = "Welcome to the home of [DRags](https://www.youtube.com/@_DRags). Explore the **2 year old** server and see what we have to offer!")
        await interaction.channel.send(embed=embed, view=view)
        await interaction.response.send_message(f"The information message has been sent in {interaction.channel}!", ephemeral=True)

async def setup(bot):
    await bot.add_cog(info(bot))

Please note that there a more commands in this cog that I removed for simplicity.
The structure of rules in variables.py
rules = ["rule name|rule description","rule name|rule description"]

So basically I want to find out how I could make the buttons on this command persistent and I have linked the screenshot of the command here too.
Answer: Change your view to be class-based, it's gonna be easier to manage.
class MyPersistentView(discord.ui.View):
    def __init__(self):
        super().__init__(timeout=None)

    @discord.ui.button(label="Rules", custom_id="rules-button", style=discord.ButtonStyle.blurple)
    async def rules_callback(self, interaction, button):
        rulesEmbed = discord.Embed(title="Official Rules for DRags Club", description="Please agree to our guidelines.")
        for item in rules:
            rule = item.split("|")
            rulesEmbed.add_field(name=rule[0], value=rule[1], inline=False)
        await interaction.response.send_message(embed=rulesEmbed, ephemeral=True)

    @discord.ui.button(label="Verify", custom_id="verify_button", style=discord.ButtonStyle.blurple)
    async def verify_callback(self, interaction, button)
        role = get(interaction.guild.roles, name = "Member")
        await interaction.user.add_roles(role)
        await interaction.response.send_message("You have been verified!", ephemeral=True)

class info(commands.Cog):
    def __init__(self, bot):
        self.bot = bot

    createGroup = app_commands.Group(name="create", description="Allows you to create suggestions and polls")
    infoGroup = app_commands.Group(name="info", description="Shows you info")

    @app_commands.command(name="sendinfo", description="Sends the information message")
    @app_commands.check(check_is_it_us)
    async def sendinfo(self, interaction:discord.Interaction):
        view = MyPersistentView(timeout=None)
        await interaction.response.send_message(view=view)

Now to create a persistent view it's really simple. Inside the setup_hook method call bot.add_view and pass the MESSAGE_ID (you can do this by copying the message ID in discord after sending the initial message)
from cogs.info import MyPersistentView  # or wherever you defined your view class

bot = commands.Bot(command_prefix=">", intents=discord.Intents.all())

MESSAGE_ID = 0

async def setup_hook():
    bot.add_view(MyPersistentView(), message_id=MESSAGE_ID)

bot.setup_hook = setup_hook

Comment: Thanks for the response. when i tried using this code I got the following error before i could even run the bot: https://imgur.com/a/8SYmFRD
Comment: https://imgur.com/a/tVlWlf2 this is the new code for  the command btw and i didnt change anything from the class except adding a colon or something like that
Comment: Do you have any idea as to why I got that error?
Comment: Just set a custom ID for each button (edited my answer). The error is pretty self-explanatory.
Comment: ok so now i get a typerror, which according to the [API Reference](https://discordpy.readthedocs.io/en/latest/ext/commands/api.html?highlight=bot%20add_view#discord.ext.commands.Bot.add_view), happened because a view was not passed. I want my bot to send the information message with the buttons then the buttons never reset after restarting my bot. [Screenshot of error](https://imgur.com/a/cwqFbFw)
Comment: shoot sorry, add_view is not a coroutine, it shouldn't be awaited. i edited my answer
Comment: I also had to add [this bit](https://imgur.com/a/xOPJQ01), which I copied from the [example](https://github.com/Rapptz/discord.py/blob/master/examples/views/persistent.py) to remove the first ValueError along with adding the `custom_id`s

Discord.py button persistency confusion


Sequelize relation with WHERE IN ("ARRAY")

Question: Is it possible to define a relationships in sequelize where multiple foreign keys are stored as an array in one field. Basically a belongsToMany but instead of an relation table all ids are stored comma separated in one field. Query would be with WHERE IN('1,5,7').
Answer: To get sequelize query result with where condition for given array with using **Op.in** code to find result with in array as
var Sequelize = require('sequelize');
var Op = Sequelize.Op;
var arrayofTaskId = ['123', '456', '789'];
Tasks.findAll({
  where: {
    task_id: {
      [Op.in]: arrayofTaskId
    }
  }
}).then(function(result) {
  return res.json(result)
});

Answer: You can do it, but definitely without foreign key constraints - there is no possibility of storing array of foreign keys. You can however create a column which will be an array of integers representing IDs of associated table. Then you just need to create some instanceMethods for retrieving and setting the array values (remember that the ARRAY type is only available in PostgreSQL).
I do not recommend this solution due to the fact that it does not ensure data consistency. Let's consider an example - user belongs to many categories with ids 1, 2 and 4. If you delete one of those categories, you need to remember to manually remove this id from categories array of user (with use of some hook or other tool), otherwise this user will still be assigned to a category that no longer exists.
const User = sequelize.define('User', {
    categories: DataTypes.ARRAY(DataTypes.INTEGER)
}, {
    instanceMethods: {
        getCategories: function(){
            return Category.findAll({
                where: {
                    id: { $in: this.get('categories') }
                }
            }).then(categories => {
                // if user's categories was [1, 2, 4]
                // it would return categories with id=1, id=2 and id=4
                return categories;
            });
        },
        setCategories: function(ids){
            return this.setDataValues('categories', ids).save().then(self => {
                return self;
            });
        }
    }
});

Comment: Thank you for this. A question, however: should it not be `this.setDataValue()`? *_notice the use of a singular form_
Comment: where is that `this` come from?
Comment: @AlanYong I guess it's from Model class


Powershell change path of shortcuts in all folder and subfolder

Question: can anyone please help me with my problem?
I want to change the path of shortchuts in all folders and subfolders because we have changed our server. That is why I need the code to loop through the all folders and subfolders.
The old path is defined as oldPrefix and the path as newPrefix, i have just put placeholders here.
The code currently only searches for shortcuts on desktop, I would need it to search through everything in desktop (so some kind of for loop maybe?).
$oldPrefix = "OLD SERVER"
$newPrefix = "NEW SERVER"
$searchPath = "$($env:USERPROFILE)\Desktop"

$shell = new-object -com wscript.shell
write-host "Updating shortcut target" -foregroundcolor red -backgroundcolor black

dir $searchPath -filter *.lnk -recurse | foreach {
$lnk = $shell.createShortcut( $_.fullname )
$oldPath= $lnk.targetPath
$lnkRegex = "^" + [regex]::escape( $oldPrefix )

if ( $oldPath -match $lnkRegex ) {
$newPath = $oldPath -replace $lnkRegex, $newPrefix

write-host "Found: " + $_.fullname -foregroundcolor yellow -backgroundcolor black
write-host " Replace: " + $oldPath
write-host " With: " + $newPath
$lnk.targetPath = $newPath
$lnk.Save()
}
}

thank you.
Comment: Welcome to stackoverflow.com. For any specific problem you are having please include a https://stackoverflow.com/help/minimal-reproducible-example. Please also read https://stackoverflow.com/help/how-to-ask and https://stackoverflow.com/help/dont-ask. Make sure that your questions are specific and not overly broad, see also https://stackoverflow.com/help/on-topic. Also, be sure to take the stackoverflow.com/tour (you get a badge!)
Answer: If you change your dir row to this it will be recursive and get all *.lnk files in subdirectories too.
Get-ChildItem -Path $searchPath -Filter *.lnk -Recurse | foreach {


If $ B(X) \ni \{T_n\} \to T $ invertible with $\|T_n^{−1}\|<1$ , then $T$ is invertible

Question: Let $H$ be a Hilbert space and suppose that $\{T_n\}$ is a sequence of invertible operators in $B(X)$ which converges to $T \in B(X)$. Suppose also that $\|T_n^{−1}\|<1$ for all $n \in \mathbb{N}$. Show that $T$ is invertible.
My attempt:

Thm : Let $H$ be a real Hilbert space. Let $A : H \to H$ be a bounded linear operator which is
  strictly positive definite, so that $\exists \ \beta >0 \ \ s.t. \langle A x,x\rangle \ge \beta \|x\|^2$. Then, for every $f \in H$, there exists a unique $u = A^{−1}f \in H$ such that $Au = f$ (i.e. $A$ is invertible) .
  The inverse operator $A^{−1}$ satisfies   $\|A^{−1}\|\le \frac{1}{\beta}$.

$(1)$ Since $T_n$ is is invertible for all $n \in \mathbb{N}$,  $\exists \ \beta >0 \ \ s.t. \langle T_n x,x\rangle \ge \beta \|x\|^2$ for all $n \in \mathbb{N}$. Since $\|T_n^{−1}\|<1 \implies \beta =1$.
$(2)$ Since $T_n \in B(X) , \ \forall n\in \mathbb{N}$ By uniform boundedness principle they're uniformly bounded and the limit $T$ is also linear and bounded.
$(3)$ Since $T,T_n \in B(X) , \ \forall n\in \mathbb{N}$ ,  there exists a subsequence $T_{nk}\rightharpoonup T$ i.e. $\langle T_{nk}x,x\rangle \to \langle Tx,x\rangle $,  as $k\to \infty, \ \forall x \in H$.
So from part (1) we have the $ \langle Tx,x\rangle  = \lim_{k\to \infty} \langle T_{nk}x,x\rangle \ge \|x\|^2$.
Comment: Do you think any invertible matrix is semi-definite? Your assumption in (1) is false.
Comment: an Invertible matrix $T$ is strictly positive definite, I am following "lecture notes in functional analysis, by bressan" this inequality has been given as the definition of strictly positive definite operator $T$. [page 89]
Comment: @KaviRamaMurthy , is the above comment correct?
Comment: A diagonal matrix with strictly negative diagonal entries is invertible but it is not positive definite.
Answer: It is not true that invertibility of $T_n$ gives you the inequality you stated in (1). So this method completely breaks down.
Note that $\|I-T_n^{-1}T\|=\|T_n^{-1}T_n-T_n^{-1}T\|\leq \|T_n^{-1}\|\|T_n-T\| <1$ for $n$ sufficiently large. From  the following well known fact it follows that $T_n^{-1}T$ is invertible and hence $T=T_n T_n^{-1}T$ is also invertible.
Lemma: If $S$ is a bounded operator with $\|S\| <1$ then $I-S$ is invertible
The lemma is proved by showing that the series $\sum S^{n}$ converges in operator norm and its sum is the inverse of $I-S$.
Comment: You should take the sum $\sum_n S^n$, not $\sum (I-S)^n$. Also, in your identity from the start it should be $T_n^{-1}T_n$ instead of $T_n^{-1} T$.
Comment: @PhoemueX Thanks you. Corrected both the mistakes.


Sorting entries in Ruby on Rails 4 index by date/time, not order of input

Question: This is my Rails 4 app: http://wheels2015.herokuapp.com
I want the entries (events) to be listed in chronological order, as opposed to the order in which I entered them into the database (as they are currently).
This question isn't the same as mine, but it appears to be in the general ballpark, so when a user suggested that OP look up the ActiveRecord query methods in the Rails API (http://apidock.com/rails/ActiveRecord/QueryMethods/order) I did.
Do you think this would do what I want it to?
Event.order('date_time')
=> SELECT "events".* FROM "event" ORDER BY event_date_time

This is the portion of my event controller that's responsible for the index page, as well as the event params:
 def event_params
      params.require(:event).permit(:event_name, :location, :description, :event_date_time, :organizer, :category) if params[:event]
    end

  def index
    @events = Event.all
  end

Comment: Well, why don't you try it? I don't understand the question. Do you want me to run the code for you and tell you that it works? Because your app could do the same thing for you.
Comment: is `event_date_time` the same as `created_at`? `created_at` is the timestamp when you created the entry. i think you want `Event.order('created_at')`
Comment: @rob i've added a specific field for a date and time that's different. I **don't** want it to sort in order of `created_at`, which I suspect it already does because my latest entry is last even though it will take place before several other entries I made.
Comment: I'm not sure how this question isn't answered by Rails docs and/or tutorials.
Comment: `@events = Event.order('event_date_time') => SELECT "events".* FROM "event" ORDER BY event_date_time` gives me a syntax error, so I tried plain old `@events = Event.order('event_date_time')` and it works! thanks, I think just the act of writing out the question has helped.
Answer: I think I had some minor trouble understanding the documentation, but this did what I wanted:
events_controller.rb:
  def index
    @events = Event.order('event_date_time')
  end

I swear I didn't ask this question so that I could answer it 5 minutes later; it's more like the action of writing the question helped me think through it? I don't want anyone to make the effort to write an answer, but if someone else is already in the process of working on one i'd upvote theirs instead of my own.


Como fazer para que ao submeter um form dentro de um iframe, a página que tem o iframe seja redirecionada?

Question:
Estou criando uma página que funciona assim:
A pessoa acessa uma página de cadastro, e dentro dessa página há um iframe com o formulário para o cadastro. Quando uma pessoa clica dentro do iframe em cadastrar ele redireciona para outra página que eu criei. Só que a nova página aparece dentro do iframe, e eu quero a página que contém o iframe seja redirecionada para sucesso.html.

Eu já tentei utilizar algo como target="":
<form id="form1" target="_self" method="post" action="concluido.php">

Porém continuou do mesmo jeito.
Como fazer para que a janela seja redirecionada e não o conteúdo do iframe?
Comment: Testa com `target="_blank"`, senão podes fazer com JS no `onsubmit` abrir uma nova janela.
Comment: Eu não quero que abra em uma nova janela, eu quero que quando clicar DENTRO DO IFRAME em Cadastrar, a página que tem o iframe seja redirecionada para sucesso.html
Answer: Se voce deseja abrir uma página nova, você pode colocar uma instrução na sua página contida no iframe para que quando concluir a recepção do PHP ele faça uma chamada js:

Caso deseje atualizar a página ao submit do formulário pode fazer assim:
<form action="login.php" method="post" target="_blank"></form>

Refatorando aqui:
 Se deseja que o parent(pagina pai)seja atualizada toda, após o submit, você pode fazer em php adicionando um head após a manipulação do post:
<?php
    header('Localização: suaPagina.php');
?>

Pode fazer escrevendo um js após a manipulação:

Ou pode usar a tag do formulário, submetendo toda a tela:
<form action="login.php" method="post" target="_parent"></form>

Comment: Eu não quero que abra em uma nova janela, eu quero que quando clicar DENTRO DO IFRAME em Cadastrar, a página que tem o iframe seja redirecionada para sucesso.html
Comment: Editado lá.. havia começado escrever a resposta para atualizar o parent, mas quando li o título anterior `Abrir uma nova página`, mudei o conteúdo da resposta... Espero que atenda...
Answer: Podes usar target="_parent" se tiveres um link que ao ser clicado deve abrir na página que contem o iFrame.
Se queres abrir um url especifico na página que contem a iFrame podes usar window.parent.location assim, por exemplo:
document.querySelector('a').addEventListener('click', function(e){
  e.preventDefault;
  window.parent-location = this.href;
});

Exemplo online aqui
Comment: Como ficaria para adaptar em:
``
Comment: @AlexandreLopes onde está a informação do  `url`? se for a da `` podes usar `target="_parent"` na form.


What to do first when there are violations of assumption in Simple Regression?

Question: Suppose we want to do simple linear regression. Before we do simple linear regression, we need to check these following assumptions (please correct me if I'm wrong):

Linear relationship
Normality of residual
Homoskedasticity of residual
No autocorrelation

My question is: When the data doesn't follow several or even all of the assumption, which one should be handled first?
I have several data that have one variable independent (X) and one variable dependent (Y).

My first data violates normality and autocorrelation assumption. When I handled the autocorrelation using Cochrane-Orcutt transformation, the data became normally distributed. In this case, did I only need to handle the autocorrelation issue?
My second data violates autocorrelation assumption. I handled it with the same method, but the data became non-normally distributed. What should I do?
My third data doesn't follow linearity and normality assumption. I tried to handle the normality issue first by transforming the orginal data to sqrt(X) and sqrt(Y) (I'm not sure this is right to do), then did linearity test again, and the result said that the data was linear.
My fourth data violates normality, heteroskedasticity, and autocorrelation assumption. Since transformation method will affect result of the other assumption test, which issue should be handled first to get right conclusion?
Comment: If you are worried about autocorrelation, you presumably have at least three variables, with time (or space) as well to define serial order.
Answer: You started with a premise of simple linear (in the parameters) regression but quickly mentioned autocorrelation.  Those two phrases are inconsistent.
Ignoring correlations within the data, the other problems IMHO are best dealt with by instead choosing a method that is transformation-invariant, does not assume equal variances, and does not assume a particular distribution of $Y$ for any particular $X$.  That method would be a semiparametric ordinal regression model such as the proportional odds or proportional hazards model.  Ordinal models work very well for continuous $Y$ as been discussed elsewhere on this site.
Answer: The most important assumptions are that the data is randomly sampled and that the error term and independent variables are not correlated. Only in these cases will you have wrong expected value for beta coefficient of the slope.
For autocorrelation you can simply use FGLS or HACSE, but OLS is not biased if there is autocorrelation, merely inefficient. Not a huge problem if you have lots of data.
Likewise the normality assumption is not important, if you have enough data.
Linearity of parameters assumption can not be violated if you are using OLS, it's an axiom. Rather you could have the wrong functional form for the variables. You should correct the functional form, if this is the case or the error term could be correlated with betas and OLS become biased. It will also output wrong forecasts.
Heteroscedasticity can also be corrected with FGLS, or by using HACSE. Heteroscedasticity does not lead to biased estimator either, so it's not very important.
Comment: We are starting in different places. You are assuming that the world is $y = X\beta$ and then worrying about the details of fitting the model. The practical person starts with $y, X$ and is considering what can go wrong if linear regression is applied, to which the first comment should be be careful about assuming $X\beta$. In fact, the practical person probably starts with $y$ and a bundle of other stuff to choose from that might end up in $X$. I have no disagreement about technical results, which are all of a form "if this, then that". I am just underlining that the context is wider.
Comment: I suspect that I agree with you, but mentioning "wrong functional form"  some way down the list is puzzling. The most important condition is that there is a linear relationship. Whether you call it an axiom or an assumption divides the people. Mathematically-minded statistical people take it as given, so that they can deduce how estimators work, or don't. But practically-minded statistical people start with a problem and data, and the functional form is what to worry about first. Everything else is secondary.
Comment: Clearly there are many issues around transformations, interactions, etc. in many practical contexts. But, apart from being a little amusing, the fact that I could identify your econ* background from just your wording is a reminder that there are different emphases here within statistical science. In my own field, getting a functional form that matches the underlying behaviour trumps all other considerations and all the machinery of inference is just decorative. But identifying the correct functional form is far from trivial.
Comment: Apologies, I meant linearity in parameters being an axiom. Wrong functional form of the variables violates the Gauss Markov assumptions. The first of these is the Gauss Markov assumption so I was speculating the question was regarding that (linear relationship is not a condition after all). Edited now.
Comment: Sure, I take linearity in parameters as implied. Your view is the view of writers of econometrics textbooks. The world looks differently to empirical people. Also, mainstream statistics treatments of regression are typically more relaxed and less interested in the consequences of formal deductions.
Comment: @NickCox Indeed that is the background I come from. I still don't see how the parameters can be anything but linear when using OLS  by definition... Or why OLS would be biased if you don't have a linear relationship, as you can simply use the correct functional form. Could you elaborate? I suspect you must be talking about the transformed variable and not the actual variable (feel also free to edit the answer if there is something important I am missing).


Best way to incorporate variable that is not linear among other linear variables in multiple regression?

Question: I am trying to predict a variable called epa, using 4 other variables. 3 of them are linear but this one, as you can see, is curved slightly downwards on each end (I plotted this using a Loess function). Based on my (limited) knowledge of multiple regression, it would not be useful to throw this into the equation as if it is linear like the others. Would there be a better way to incorporate it? I was thinking maybe a categorical variable that identifies whether the value is < 25, between 25 and 75, or > 75. I'm guessing this might be suboptimal though. I've tried Googling a bit but haven't had much luck, probably because I don't know what to call this non-linear variable form.

Also, I do realize this variable isn't going to be very predictive regardless. The question is more for learning purposes :)
Comment: @Dave Note that OP is only showing the the joint of temp and epa.  If there are other variables, there could very well be a non-linear relationship that is obfuscated here.
Comment: A standard recommendation to incorporate some curvature is to use splines, though I am not sold on this being a particularly useful variable or having such a nonlinear relationship with the outcome.
Comment: Use a restricted cubic spline
Answer: Here is a way you can do this with splines.
In general, we can model a non-linear process with a linear model using splines.  In this example, I will generate some data with the true functional form
$$ y = 2x + z + \sin(z) $$
I will estimate this function using
$$ \hat{y} = \beta_0 + \beta_1x + f(z) $$
Where $f(z)$ is a linear combination of basis functions.  For this example, I will be using a natural spline, but there are other ways to estimate $f(z)$ with different basis functions.
Here is some code to do this in R.
<code>library(tidyverse)
library(modelr)
library(splines)

# SImulate some data
N = 10000
x = rnorm(N)
z = rnorm(N)

# This is the true functional form
y = 2 * x + z + sin(z) + rnorm(N)

# Store data in a tibble
d = tibble(x, y, z)

# Basis functions require "knots".  Here, I am choosing them
# relatively unintelligently.
k = quantile(z, seq(0.05, 0.95, length.out = 4))

# Estimate the model.  Here the spline is specified by ns
# ns <-> natural spline
model = lm(y ~ x + ns(z, knots = k), data = d)

# Predict on new data and plot
d %>%
  data_grid(x = c(-1,0, 1), z) %>%
  add_predictions(model) %>%
  ggplot(aes(z, pred, color = factor(x))) +
  geom_line()
</code>
Here is the result.  Note that $f(z)$ conditional on z is non-linear even though we estimated it through a linear model.  Additionally, as x changes, $f(z)$ moves up or down (simply because x is an additive effect).


How to click an option from the dropdown, If the elements are not stored in an array

Question: When i clicked on inspect element then below is my code:
<select _ngcontent-c2="" class="form-control ng-pristine ng-invalid ng-touched" id="type" name="Type" required="">
     <option _ngcontent-c2="" disabled="" value="0: null">Type</option>
     <option _ngcontent-c2="" value="1: account">
       account
     </option><option _ngcontent-c2="" value="2: booking">
       booking
     </option>
</select>

I want to click on option "1" which is account, below is the code which i tried:
List <WebElement> Type= driver.findElements(By.id("type"));
Type.get(1).click();

But my script is not clicking on the element on which i want to click. Can someone please help me?
Comment: Show your approach, please… Is it really Java you are using or is it rather JavaScript?
Comment: Java or JavaScript? And I don't see any SQL in the question. Please correct the tags accordingly.
Comment: Don't post code in comments. Edit your question instead and format the code appropriately.
Comment:
Type

           account

           booking

Comment: @deHaar   driver.findElement(By.id("type")).click();
  Thread.sleep(2000);
  List  Type= driver.findElements(By.id("type"));
  Type.get(1).click(); This is the way i am trying
Comment:
Type

           account

           booking

The code which i tried:
List  Type= driver.findElements(By.id("type"));
  Type.get(1).click();

Some how my total question is now displaying
Comment: @deHaar i am using java only
Comment: driver.findElement(By.id("type")).send_keys("option1 name here")
Comment: Please post formatted code in your question (edit it), so everyone reading it may spend less time reading your comments that include code.
Answer: You can use select class as given below.
Select sel = new Select(driver.findElements(By.id("type")));
sel.selectByVisibleText("account");

Answer: Try this code :
List<WebElement> dropDown =   driver.findElements(By.id("type"));

for(WebElement dd : dropDown ){
           if(dd.getText().contains("account")){
                dd.click();
             }
         }

I do not know why you have not tried Select class which is present in Selenium. For that something like :
Select select = new Select(driver.findElement(By.id("type")));
select.selectByVisibleText("account");
//OR
//select .selectByIndex(1);
//OR
//select .selectByValue("1");

Comment: @ cruisepandey I am a beginner just started automation i don't know about select class
Comment: @NarendraChetan : That is fine , you can try the first code as well as second one. update the result here.
Comment: the second one works for me thank you very much for your timely help
Comment: second one works for me, if you don't mind can u help me with the random selection as i have multiple options please
Comment: Yeah sure. Which element you want to select ?
Comment: want to select any one of the element randomly in that 2 options
Comment: Its a drop down , right ? What do you mean by random here ? All you have are 2 web element. Please elaborate if there is any multi select. Remember multi select differs from drop down.
Comment: can you share the code for multi select ? I think I did not get you on the first sight
Comment: actually i have two options right one is account and other one is booking. So as per the code shared by u every time i need to select only one option either accounting or booking but i want to select one of them randomly meaning when i run my script first time if it is taking the accounting then if  run the script again it has to take booking so ultimately some times it should pick accounting and sometimes booking]
Comment: @NarendraChetan : You can generate random number between 0 and 1 (sometimes 0 or sometimes 1) using this method : public static int randomBetween0OR1() {
  Random random = new Random();
  boolean res=   random.nextBoolean();

  if(res)
   return 1;
  else
   return 0;
 }
Comment: then call this : select .selectByIndex(randomBetween0OR1());
Comment: @NarendraChetan : If this is helpful for you , you can mark this question as accepted by clicking on check mark which is just under the down vote button and besides my answer.
Comment: Great!! Thank you very much for your support @cruisepandey
Comment: No Problem bud ;)
Answer: Since it is a dropdown it is better to use Select class,
Try this code below and import the correct libraries. Library is also mentioned below,
import org.openqa.selenium.support.ui.Select;

Code,
String value = "account";
Select select = new Select(driver.findElement(By.xpath("//*[@id='type']")));
select.selectByVisibleText(value);

Answer: directly u can write this code it goes to account

import org.openqa.selenium.Keys
driver.findElement(By.id("type")).send_keys("account");
Comment: it takes input as account


Redis - JUnit - Caused by: java.net.UnknownHostException: localhost

Question: I have a SpringBoot application where I connect to Redis and it works on cloud environment:
 RedisStandaloneConfiguration redisStandaloneConfiguration = new RedisStandaloneConfiguration();
 redisStandaloneConfiguration.setHostName("localhost");
 redisStandaloneConfiguration.setPort(6379);
 redisStandaloneConfiguration.setPassword(REDIS_PASSWORD);
 LettuceConnectionFactory lettuceConnectionFactory = new LettuceConnectionFactory(redisStandaloneConfiguration, clientConfig);
 lettuceConnectionFactory.setValidateConnection(true);

Now i started a local Redis instance on localhost and port 6379; I tried to write a Junit test that uses Redis and I got the following
exception
Caused by: io.lettuce.core.RedisConnectionException: Unable to connect to  localhost:6379
    at io.lettuce.core.RedisConnectionException.create(RedisConnectionException.java:78)
    at io.lettuce.core.RedisConnectionException.create(RedisConnectionException.java:56)
    at io.lettuce.core.AbstractRedisClient.getConnection(AbstractRedisClient.java:320)
    at io.lettuce.core.RedisClient.connect(RedisClient.java:211)
    at org.springframework.data.redis.connection.lettuce.StandaloneConnectionProvider.lambda$getConnection$1(StandaloneConnectionProvider.java:115)
    at java.util.Optional.orElseGet(Optional.java:267)
    at org.springframework.data.redis.connection.lettuce.StandaloneConnectionProvider.getConnection(StandaloneConnectionProvider.java:115)
    at org.springframework.data.redis.connection.lettuce.LettuceConnectionFactory$ExceptionTranslatingConnectionProvider.getConnection(LettuceConnectionFactory.java:1459)
    ... 17 common frames omitted
Caused by: java.net.UnknownHostException:  localhost
    at java.net.InetAddress.getAllByName0(InetAddress.java:1281)
    at java.net.InetAddress.getAllByName(InetAddress.java:1193)
    at java.net.InetAddress.getAllByName(InetAddress.java:1127)
    at java.net.InetAddress.getByName(InetAddress.java:1077)

Any hints?
I tried:

localhost
127.0.0.1
put localhost 127.0.0.1 in hosts file

But got the same exception
Comment: can you please share the output of this command
netstat -aon | find /i "listening" |find "6379"
Comment: can you try with the ip address returned from "ipconfig" command? Also, are you trying to connect via proxy in code level? If so, pls try disabling proxy..
Comment: Yes, I tried all the Ips shown in ipconfig output:
10.0.0.5, 10.223.252.108,192.168.56.1
Comment: TCP    0.0.0.0:6379           0.0.0.0:0              LISTENING       14984
Comment: can you please try updating "redis.conf" file with "protected-mode" property from yes to no?
Comment: Running redis-cli gives me below output with hostname & Port # as part of it. Can you please share what do you see in your case? Thank you!

127.0.0.1:6379>
Answer: After some hours I found the problem:
redis.cluster.nodes:${REDIS_CLUSTER_NODES: localhost:6379;}

If I put
redis.cluster.nodes: localhost:6379;

it works fine