"Non-existent service" errors after clearing the cache

Question: After clearing the cache in Drupal 8 (via the UI) I got "The website encountered an unexpected error. Please try again later." error. It happened for the first time. I haven't introduced any heavy changes to the site, basically only created a field and some features (via the Features module).
I've found this error in the logs:

Symfony\Component\DependencyInjection\Exception\ServiceNotFoundException: You have requested a non-existent service "password_migrate". in /.../app/vendor/symfony/dependency-injection/ContainerBuilder.php on line 800

To fix this was trying different things: clearing cache tables directly in the DB, trying drush rebuild (rebuild wasn't successful since it yelds the same error). After some time the error is different (and I don't know why):

Symfony\Component\DependencyInjection\Exception\ServiceNotFoundException: The service "ctools.paramconverter.tempstore" has  a dependency on a non-existent service "user.shared_tempstore". in /.../app/vendor/symfony/dependency-injection/  Compiler/CheckExceptionOnInvalidReferenceBehaviorPass.php on line 58

I can temporarily get the site back to life by loading {cache_container} table from the old backup. But the site breaks again after clearing the cache and the first error reapers in logs.
The site is basically broken. How can I restore it? How is the {cache_container} populated, so I can reverse the process and restore what's missing based on the cache? Thanks!
Comment: When you get your site back, is there anything on admin/reports/status?
Comment: @MPD, thanks for the answer. Apart from "Trusted Host Settings", "Cron jobs" (to be run) and "Database version" (which I cannot update due to the error), there's also: "Entity/field definitions": "Mismatched entity and/or field definitions", but I don't think any of those is a cause of the problem.
Answer: It took me a while, but I managed to find the issue and to solve it.
The problem was directly caused by the Features module (or maybe rather it was directly caused by careless me...). Anyway, a couple of hours before I cleared the cache (this is when the issue manifested itself) I had exported some configuration as new features. Normally I would use some custom names, but this time I've just swum with the tide and added the configuration to the features that Features module proposed. And one of the proposed features was "User" with machine name "user", which is exactly the same as the core module! This is why "password_migrate" service couldn't be found, Drupal was looking at the new feature instead of the core module.
Because the module name was already in core.extension configuration I didn't even have to enable it, as it was already enabled (unlike in the old {system} table there's no path to the module in the config so probably Drupal just used the first definition it found). After exporting the feature the problem was there, sleeping, and it was just when I cleared the cache some time later when the site broke (probably if the problem appeared right away I could track it down much earlier).
The problem went away as soon as I deleted the feature.
Comment: You saved my day!
Answer: It seems that a class is requesting the password_migrate service which does not exist.
This is usually caused when the module that supplies this service is not installed.
I suggest you search the project code for the string password_migrate to find both the requester and the provider.
Comment: Thanks for the answer. `password_migrate` service is provided by the core user module (and the service's class `MigratePassword` exists in the module). I couldn't find any dependency on this service, but there's a `$container->setDefinition('password', $container->getDefinition('password_migrate'));` call in the very same module in the `UserServiceProvider` class. The user module is enabled.
Comment: What version (including minor) of drupal are you running?
Comment: Pretty weird. `admin/reports/status` says it's 8.0.6, but in `web/core/CHANGELOG.txt` the most recent entry is 8.0.4.


How do I return a value and a JSX element using the ternary operator?

Question: I'm trying to do two things at once when someone clicks on a button to send an email. The code below changes the text of the button to "Sending..." and adds the JSX element <CircularProgress/>
<Button
    className={submitButton}
    type="submit"
    disabled={emailStatus === "loading"}
    >
{emailStatus === "loading" ? ("Sending..." ): "Send Email"}
{emailStatus === "loading" && (<CircularProgress size={24}/>)}
 </Button>

As you can see I'm checking the email status twice using the ternary operator.
How can I put it all into one, maybe like this, but it doesn't work:
<Button
    className={submitButton}
    type="submit"
    disabled={emailStatus === "loading"}
    >
{emailStatus === "loading" ? ("Sending..." , <CircularProgress size={24}/> ): "Send Email"}
 </Button>

Answer: You can put them inside one parent element and then render that.
<>
 Sending ...
 <CircularProgress size={24}/>
</>

Comment: Thank you so much! Exactly what I was looking for :)


what are the php commands to create and retrieve password with SHA-256 encryption?

Question: Newbie here. I'm trying to encrypt the user password using SHA-256 after they've made their account and then when the user tries to log in, it will try to match their input with any of the encrypted passwords in the mysql database. I was wondering if someone could give me an example code?
Comment: SHA-256 is not an encryption function but a hash function.
Answer: Hashing works one-way, so you cannot really 'retrieve' what you have hashed.
When you save the password on registration, use something like this:
$hash=hash('sha256', $password);

And only save $hash in the database. When the user tries to log in, hash the password he tries to use and compare it to the one in the database (hashing will always give the same result for the same input). If they are the same, he can be logged in (if all additional checks are satisfied).
If you want to let the user recover his forgotten pass, refer to this earlier question.
Also, the best practice in hashing passwords is to use some kind of salt, which is out of the scope of this question, but please google it.
Comment: but _please_ "salt" the password first (i.e. concatenate a secret string) so that people with databases of SHA256 hashes can't look for matches.
Comment: @user701510 An SHA256 hash is always 64 characters long. That means your best bet would be a `CHAR(64)` (you don't need `VARCHAR`). [See also this SO thread](http://stackoverflow.com/questions/2240973/php-when-using-a-sha256-hash-how-long-is-the-hash-ie-how-long-should-my-mys)
Comment: what variable type do I associate with the hashed password in the mysql table?
Answer: If using PHP >= 5.5, you should be using password_hash() for storing passwords, and password_verify() to check. If using PHP >= 5.3, you should be using this compatibility module. If using an earlier version of PHP, you should upgrade.
Do not roll your own password hashing. There is no stressing this enough. Take a look at John the Ripper to see how fast passwords that have only been hashed with cryptographic hashes (that are designed to be fast!) can be cracked.


Logistic regression - handling very few observations for a level of a categorical variable

Question: Context
I'm not sure what to do in the scenario where one of the levels for a variable
has so few levels that there's a good chance splitting the data into $70\%$
training $30\%$ testing will result in the level being completely contained in
either test or train.
For example with the following data:
> table(testset$x1)

BL BM BR ML MM MR TL TR
90  5 76 19  8 10  2  2
> table(trainset$x1)

BL  BM  BR  ML  MM  MR  TL  TR
217  10 182  37  20  27   1   0

Here BL=bottom-left, MM=middle-middle, TR=top-right.
Given that there are so few observations for TL,TM,TR (actually zero for TM)
it's quite likely that they could all be contained in either test / training. If
this happens then prediction for that is problematic.
Reordering the variable
The levels could be merged from
BL BM BR ML MM MR TL TR -> B M T
                        -> B NB

Where B,NB represent bottom, not-bottom respectively.
This would greatly reduce the probability of either test / training containing
the entirity of the level, but it feels as though it's a pretty extreme
distortion. Perhaps to the degree that it's no longer usable.
Model
Currently the model is constructed as
m <- glm(y ~ x1 + x2, data = trainset, family="binomial")

Which throws an error after trying to use it for prediction (as the entirity of
one level is contained within one set for the given random seed).
Constructing the model as :
m <- glmer(y ~ (1|x1) + x2, data=df, family="binomial" )

Stops this error from occuring, where x1 is modelled as a random effect. I'm
not sure if this makes sense though, because I actually wanted to use this for
prediction, rather than just controlling for its variation.
But perhaps I'm a bit confused about what a random effect really means here.
R Code
Here is a link to a pastebin of this code which may / may not be easier to copy into an editor.
df <- structure(list(x1 = structure(c(1L, 4L, 1L, 1L, 1L, 1L, 1L, 1L,
                                      5L, 1L, 1L, 3L, 1L, 1L, 3L, 6L, 1L, 1L, 1L, 3L, 1L, 1L, 4L, 3L,
                                      3L, 4L, 1L, 1L, 5L, 5L, 4L, 3L, 3L, 3L, 1L, 1L, 3L, 3L, 3L, 1L,
                                      1L, 1L, 4L, 1L, 1L, 3L, 1L, 3L, 1L, 1L, 1L, 6L, 3L, 3L, 1L, 1L,
                                      1L, 1L, 3L, 1L, 1L, 1L, 8L, 3L, 3L, 4L, 3L, 1L, 1L, 3L, 1L, 3L,
                                      1L, 1L, 1L, 3L, 1L, 4L, 3L, 4L, 3L, 4L, 1L, 3L, 1L, 1L, 4L, 1L,
                                      1L, 3L, 2L, 1L, 1L, 1L, 3L, 3L, 1L, 1L, 1L, 1L, 3L, 1L, 1L, 3L,
                                      1L, 1L, 3L, 1L, 3L, 3L, 1L, 3L, 1L, 1L, 3L, 1L, 3L, 3L, 4L, 1L,
                                      3L, 6L, 3L, 3L, 1L, 1L, 5L, 3L, 3L, 3L, 3L, 3L, 3L, 1L, 1L, 3L,
                                      3L, 3L, 3L, 4L, 3L, 1L, 1L, 1L, 6L, 4L, 3L, 1L, 3L, 3L, 3L, 1L,
                                      1L, 1L, 3L, 1L, 3L, 1L, 1L, 5L, 1L, 1L, 1L, 3L, 3L, 3L, 3L, 1L,
                                      1L, 6L, 3L, 1L, 1L, 4L, 3L, 4L, 4L, 3L, 3L, 1L, 1L, 6L, 1L, 1L,
                                      3L, 8L, 1L, 1L, 1L, 1L, 3L, 1L, 1L, 5L, 5L, 1L, 5L, 1L, 1L, 1L,
                                      3L, 1L, 3L, 1L, 1L, 1L, 1L, 3L, 3L, 1L, 1L, 3L, 6L, 3L, 1L, 1L,
                                      3L, 1L, 4L, 1L, 1L, 1L, 1L, 6L, 1L, 1L, 3L, 3L, 3L, 3L, 1L, 1L,
                                      3L, 1L, 3L, 3L, 1L, 1L, 1L, 3L, 3L, 3L, 3L, 4L, 4L, 1L, 3L, 1L,
                                      3L, 3L, 4L, 1L, 3L, 5L, 3L, 1L, 3L, 3L, 5L, 1L, 3L, 1L, 1L, 3L,
                                      5L, 4L, 1L, 1L, 1L, 1L, 6L, 3L, 3L, 6L, 1L, 6L, 1L, 1L, 1L, 1L,
                                      1L, 5L, 1L, 1L, 1L, 5L, 3L, 1L, 1L, 1L, 3L, 3L, 3L, 7L, 1L, 4L,
                                      5L, 3L, 3L, 1L, 3L, 1L, 1L, 3L, 1L, 1L, 4L, 1L, 1L, 4L, 1L, 3L,
                                      6L, 3L, 3L, 2L, 1L, 3L, 1L, 2L, 6L, 3L, 4L, 3L, 4L, 1L, 6L, 3L,
                                      3L, 1L, 1L, 1L, 1L, 3L, 1L, 3L, 3L, 3L, 3L, 3L, 1L, 1L, 1L, 1L,
                                      3L, 3L, 3L, 1L, 6L, 3L, 3L, 1L, 1L, 3L, 4L, 1L, 1L, 1L, 1L, 3L,
                                      3L, 3L, 1L, 3L, 1L, 1L, 1L, 6L, 3L, 1L, 1L, 3L, 1L, 1L, 6L, 3L,
                                      3L, 3L, 1L, 3L, 1L, 4L, 6L, 1L, 3L, 1L, 3L, 1L, 3L, 3L, 1L, 1L,
                                      1L, 3L, 3L, 3L, 3L, 1L, 3L, 3L, 3L, 6L, 1L, 3L, 1L, 3L, 3L, 4L,
                                      3L, 3L, 1L, 1L, 3L, 1L, 3L, 3L, 1L, 6L, 6L, 4L, 4L, 1L, 3L, 2L,
                                      5L, 3L, 2L, 2L, 2L, 3L, 4L, 3L, 6L, 3L, 3L, 3L, 4L, 1L, 3L, 1L,
                                      6L, 4L, 1L, 3L, 3L, 3L, 1L, 5L, 2L, 6L, 3L, 1L, 1L, 3L, 3L, 5L,
                                      3L, 1L, 2L, 1L, 6L, 1L, 1L, 1L, 1L, 1L, 1L, 2L, 3L, 6L, 4L, 3L,
                                      3L, 1L, 1L, 1L, 6L, 1L, 3L, 6L, 1L, 1L, 6L, 5L, 1L, 1L, 1L, 1L,
                                      3L, 3L, 4L, 3L, 3L, 1L, 1L, 1L, 1L, 3L, 4L, 1L, 4L, 1L, 3L, 3L,
                                      1L, 6L, 4L, 4L, 1L, 3L, 4L, 3L, 1L, 3L, 5L, 3L, 1L, 3L, 5L, 3L,
                                      3L, 3L, 3L, 1L, 3L, 1L, 1L, 1L, 3L, 3L, 4L, 1L, 3L, 3L, 3L, 3L,
                                      3L, 3L, 4L, 1L, 3L, 3L, 3L, 1L, 1L, 4L, 1L, 1L, 6L, 1L, 2L, 6L,
                                      NA, 6L, 7L, 1L, 3L, 6L, 1L, 3L, 3L, 7L, 4L, 1L, 4L, 1L, 1L, 2L,
                                      3L, 4L, 3L, 1L, 4L, 1L, 3L, 1L, 4L, 1L, 1L, 3L, 1L, 3L, 3L, 1L,
                                      1L, 1L, 5L, 1L, 1L, 3L, 3L, 3L, 3L, 1L, 1L, 1L, 3L, 3L, 3L, 3L,
                                      3L, 5L, 3L, 1L, 1L, 5L, 3L, 3L, 3L, 1L, 3L, 1L, 1L, 1L, 3L, 1L,
                                      3L, 3L, 5L, 3L, 3L, 1L, 3L, 3L, 3L, 1L, 1L, 1L, 5L, 1L, 1L, 1L,
                                      4L, 1L, 3L, 3L, 1L, 1L, 1L, 1L, 1L, 1L, 6L, 1L, 1L, 3L, 1L, 3L,
                                      3L, 3L, 1L, 3L, 3L, 3L, 3L, 1L, 1L, 1L, 4L, 3L, 3L, 3L, 1L, 1L,
                                      1L, 1L, 3L, 1L, 1L, 1L, 6L, 1L, 1L, 3L, 3L, 4L, 4L, 1L, 1L, 1L,
                                      5L, 3L, 3L, 3L, 4L, 1L, 2L, 3L, 2L, 6L, 2L, 3L, 5L, 1L, 3L, 3L,
                                      3L, 3L, 1L, 4L, 3L, 1L, 4L, 1L, 3L, 1L, 5L), .Label = c("BL",
                                                                                "BM", "BR", "ML", "MM", "MR", "TL", "TR"), class = "factor"),
                     x2 = structure(c(3L, 1L, 2L, 2L, 1L, 1L, 3L, 2L, 1L, 3L,
                                      1L, 1L, 1L, 2L, 2L, 2L, 1L, 2L, 1L, 3L, 3L, 1L, 2L, 2L, 2L,
                                      2L, 1L, 2L, 1L, 2L, 2L, 1L, 2L, 1L, 1L, 3L, 1L, 2L, 1L, 1L,
                                      1L, 2L, 2L, 1L, 1L, 1L, 1L, 3L, 2L, 1L, 2L, 3L, 1L, 1L, 1L,
                                      1L, 1L, 3L, 1L, 3L, 1L, 1L, 1L, 1L, 2L, 1L, 1L, 1L, 2L, 2L,
                                      1L, 1L, 1L, 3L, 2L, 1L, 2L, 3L, 2L, 1L, 1L, 3L, 1L, 3L, 3L,
                                      2L, 1L, 1L, 1L, 1L, 1L, 3L, 1L, 3L, 2L, 3L, 2L, 1L, 1L, 1L,
                                      1L, 3L, 2L, 2L, 1L, 1L, 1L, 1L, 1L, 3L, 3L, 1L, 3L, 1L, 1L,
                                      1L, 3L, 2L, 1L, 1L, 1L, 1L, 3L, 1L, 1L, 1L, 2L, 2L, 2L, 1L,
                                      2L, 3L, 1L, 1L, 1L, 1L, 1L, 2L, 1L, 3L, 2L, 3L, 2L, 1L, 2L,
                                      1L, 1L, 2L, 1L, 2L, 1L, 1L, 1L, 1L, 1L, 3L, 2L, 3L, 1L, 3L,
                                      1L, 3L, 1L, 3L, 1L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L,
                                      1L, 1L, 2L, 2L, 1L, 1L, 3L, 3L, 3L, 2L, 3L, 3L, 3L, 3L, 1L,
                                      1L, 1L, 3L, 3L, 1L, 1L, 2L, 3L, 1L, 1L, 3L, 1L, 1L, 2L, 2L,
                                      1L, 1L, 3L, 3L, 2L, 1L, 2L, 2L, 1L, 1L, 2L, 2L, 1L, 1L, 2L,
                                      3L, 1L, 3L, 1L, 2L, 1L, 1L, 3L, 1L, 1L, 1L, 1L, 2L, 1L, 2L,
                                      1L, 2L, 1L, 1L, 2L, 1L, 1L, 1L, 1L, 3L, 1L, 2L, 2L, 1L, 2L,
                                      1L, 1L, 2L, 1L, 2L, 1L, 1L, 1L, 2L, 3L, 1L, 1L, 3L, 1L, 3L,
                                      2L, 2L, 2L, 1L, 2L, 2L, 1L, 2L, 1L, 1L, 3L, 2L, 2L, 1L, 1L,
                                      1L, 2L, 1L, 1L, 3L, 3L, 2L, 2L, 1L, 1L, 3L, 3L, 1L, 2L, 3L,
                                      3L, 3L, 1L, 3L, 3L, 3L, 1L, 3L, 1L, 2L, 3L, 3L, 2L, 1L, 2L,
                                      3L, 1L, 1L, 3L, 3L, 3L, 1L, 1L, 3L, 1L, 1L, 1L, 2L, 3L, 3L,
                                      2L, 2L, 1L, 2L, 3L, 3L, 2L, 1L, 1L, 2L, 1L, 1L, 2L, 1L, 2L,
                                      1L, 1L, 1L, 1L, 1L, 1L, 2L, 1L, 1L, 2L, 3L, 1L, 1L, 1L, 3L,
                                      1L, 3L, 2L, 1L, 1L, 1L, 3L, 2L, 3L, 1L, 1L, 1L, 2L, 2L, 1L,
                                      3L, 1L, 1L, 2L, 1L, 2L, 2L, 2L, 2L, 1L, 1L, 3L, 1L, 1L, 3L,
                                      2L, 1L, 1L, 2L, 2L, 1L, 3L, 1L, 1L, 3L, 3L, 1L, 1L, 1L, 1L,
                                      1L, 1L, 2L, 1L, 3L, 2L, 2L, 1L, 3L, 1L, 2L, 2L, 2L, 2L, 1L,
                                      1L, 1L, 3L, 2L, 3L, 2L, 3L, 3L, 1L, 1L, 1L, 2L, 1L, 1L, 3L,
                                      2L, 3L, 3L, 2L, 1L, 3L, 1L, 1L, 1L, 3L, 1L, 2L, 1L, 3L, 2L,
                                      1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 2L, 2L, 3L, 1L, 3L, 3L, 1L,
                                      3L, 2L, 1L, 1L, 3L, 3L, 2L, 1L, 3L, 2L, 2L, 1L, 2L, 3L, 1L,
                                      1L, 1L, 1L, 1L, 3L, 1L, 1L, 1L, 3L, 1L, 3L, 1L, 2L, 2L, 1L,
                                      3L, 1L, 2L, 1L, 1L, 1L, 2L, 1L, 1L, 1L, 1L, 1L, 3L, 1L, 2L,
                                      3L, 1L, 1L, 2L, 1L, 1L, 3L, 2L, 1L, 2L, 1L, 1L, 1L, 1L, 1L,
                                      1L, 3L, 1L, 1L, 1L, 1L, 1L, 1L, 2L, 3L, 2L, 2L, 1L, 2L, 1L,
                                      2L, 1L, 2L, 2L, 2L, 2L, 1L, 1L, 2L, 1L, 2L, 1L, 2L, 2L, 1L,
                                      3L, 3L, 2L, 1L, 1L, 3L, 1L, 2L, 2L, 3L, 1L, 1L, 1L, 1L, 1L,
                                      3L, 2L, 3L, 1L, 1L, 1L, 2L, 1L, 1L, 2L, 2L, 1L, 1L, 2L, 3L,
                                      3L, 1L, 1L, 1L, 3L, 2L, 3L, 1L, 3L, 3L, 1L, 2L, 2L, 1L, 3L,
                                      3L, 3L, 1L, 2L, 3L, 3L, 3L, 2L, 1L, 2L, 1L, 1L, 1L, 2L, 1L,
                                      3L, 2L, 2L, 2L, 1L, 1L, 3L, 2L, 1L, 1L, 2L, 2L, 2L, 1L, 1L,
                                      1L, 3L, 2L, 3L, 1L, 3L, 1L, 1L, 1L, 1L, 2L, 1L, 2L, 3L, 1L,
                                      2L, 2L, 1L, 2L, 3L, 3L, 1L, 1L, 1L, 2L, 1L, 3L, 3L, 2L, 1L,
                                      1L, 2L, 2L, 2L, 1L, 3L, 3L, 1L, 1L, 3L, 2L, 3L, 1L, 2L, 1L,
                                      2L, 3L, 1L, 1L, 1L, 1L, 2L, 3L, 1L, 1L, 1L, 1L, 2L, 2L, 2L,
                                      1L, 1L, 2L, 1L, 1L, 1L, 3L, 1L, 2L, 2L, 1L, 1L, 2L, 2L, 1L,
                                      2L, 2L, 1L, 3L, 2L, 1L, 2L), .Label = c("MEDIUM", "OLD",
                                                                              "YOUNG"), class = "factor"), y = c(1L, 0L, 1L, 1L, 1L, 1L,
                                                                                1L, 1L, 1L, 0L, 1L, 1L, 1L, 1L, 1L, 0L, 1L, 0L, 1L, 1L, 1L,
                                                                                1L, 0L, 0L, 0L, 1L, 1L, 1L, 1L, 1L, 0L, 0L, 1L, 1L, 0L, 0L,
                                                                                0L, 0L, 1L, 1L, 1L, 0L, 1L, 0L, 1L, 1L, 0L, 1L, 1L, 0L, 1L,
                                                                                0L, 1L, 1L, 1L, 0L, 1L, 1L, 1L, 1L, 0L, 1L, 0L, 1L, 1L, 1L,
                                                                                0L, 0L, 1L, 1L, 0L, 1L, 0L, 1L, 1L, 1L, 1L, 0L, 1L, 1L, 1L,
                                                                                1L, 0L, 1L, 1L, 1L, 0L, 0L, 1L, 1L, 0L, 1L, 1L, 1L, 1L, 1L,
                                                                                1L, 1L, 1L, 1L, 1L, 1L, 0L, 1L, 1L, 1L, 1L, 1L, 1L, 0L, 1L,
                                                                                0L, 1L, 0L, 1L, 0L, 0L, 1L, 0L, 0L, 1L, 1L, 0L, 1L, 1L, 1L,
                                                                                1L, 0L, 1L, 0L, 1L, 1L, 1L, 1L, 1L, 0L, 0L, 1L, 0L, 1L, 1L,
                                                                                1L, 1L, 1L, 1L, 0L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 0L, 1L,
                                                                                0L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 0L, 1L, 1L, 1L, 1L, 0L, 1L,
                                                                                1L, 1L, 1L, 1L, 0L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L,
                                                                                1L, 1L, 1L, 1L, 0L, 1L, 0L, 1L, 0L, 1L, 1L, 1L, 1L, 1L, 1L,
                                                                                0L, 1L, 1L, 1L, 1L, 0L, 1L, 1L, 1L, 0L, 0L, 1L, 0L, 1L, 1L,
                                                                                1L, 1L, 0L, 1L, 1L, 1L, 1L, 1L, 0L, 0L, 0L, 1L, 0L, 1L, 0L,
                                                                                1L, 1L, 1L, 1L, 1L, 0L, 1L, 1L, 1L, 1L, 1L, 0L, 1L, 1L, 1L,
                                                                                1L, 1L, 1L, 1L, 1L, 0L, 1L, 1L, 1L, 1L, 1L, 0L, 1L, 1L, 1L,
                                                                                1L, 1L, 1L, 0L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L,
                                                                                1L, 1L, 0L, 1L, 1L, 0L, 1L, 0L, 1L, 1L, 0L, 0L, 0L, 1L, 1L,
                                                                                1L, 1L, 0L, 1L, 1L, 1L, 1L, 1L, 1L, 0L, 1L, 1L, 1L, 1L, 1L,
                                                                                0L, 1L, 1L, 0L, 1L, 1L, 0L, 1L, 0L, 1L, 1L, 1L, 0L, 1L, 0L,
                                                                                1L, 1L, 1L, 0L, 1L, 1L, 0L, 0L, 1L, 1L, 1L, 0L, 1L, 1L, 0L,
                                                                                1L, 0L, 1L, 0L, 0L, 1L, 1L, 1L, 1L, 1L, 0L, 1L, 1L, 1L, 1L,
                                                                                1L, 1L, 1L, 1L, 1L, 0L, 1L, 1L, 0L, 1L, 1L, 0L, 1L, 0L, 0L,
                                                                                1L, 0L, 1L, 1L, 1L, 1L, 1L, 1L, 0L, 1L, 0L, 1L, 1L, 1L, 1L,
                                                                                1L, 1L, 0L, 1L, 0L, 0L, 0L, 0L, 1L, 0L, 1L, 1L, 1L, 0L, 1L,
                                                                                1L, 1L, 1L, 1L, 1L, 0L, 1L, 1L, 1L, 0L, 0L, 0L, 1L, 1L, 1L,
                                                                                1L, 0L, 1L, 0L, 1L, 1L, 0L, 0L, 1L, 1L, 1L, 1L, 1L, 0L, 1L,
                                                                                1L, 0L, 0L, 1L, 1L, 1L, 1L, 1L, 0L, 1L, 1L, 1L, 1L, 1L, 0L,
                                                                                1L, 0L, 1L, 1L, 0L, 1L, 0L, 0L, 0L, 0L, 1L, 1L, 1L, 1L, 1L,
                                                                                1L, 1L, 1L, 1L, 0L, 1L, 0L, 0L, 1L, 0L, 1L, 0L, 1L, 1L, 1L,
                                                                                1L, 0L, 1L, 1L, 1L, 0L, 1L, 0L, 0L, 1L, 0L, 0L, 1L, 0L, 1L,
                                                                                1L, 1L, 1L, 0L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 0L,
                                                                                1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 0L, 0L, 0L, 1L, 1L, 0L, 0L,
                                                                                0L, 1L, 1L, 0L, 1L, 1L, 0L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 0L,
                                                                                1L, 1L, 1L, 0L, 1L, 1L, 1L, 1L, 1L, 0L, 0L, 1L, 1L, 1L, 0L,
                                                                                1L, 1L, 1L, 0L, 0L, 1L, 1L, 1L, 0L, 0L, 1L, 1L, 0L, 1L, 1L,
                                                                                1L, 1L, 1L, 1L, 0L, 1L, 1L, 0L, 0L, 0L, 1L, 1L, 1L, 1L, 1L,
                                                                                1L, 0L, 0L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 0L, 1L, 1L, 1L, 1L,
                                                                                1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 0L, 1L, 1L,
                                                                                1L, 1L, 1L, 1L, 1L, 1L, 0L, 1L, 0L, 0L, 1L, 1L, 1L, 1L, 1L,
                                                                                1L, 1L, 1L, 1L, 1L, 1L, 1L, 0L, 1L, 1L, 1L, 1L, 0L, 0L, 1L,
                                                                                0L, 0L, 1L, 0L, 0L, 1L, 1L, 1L, 1L, 1L, 1L, 0L, 1L, 1L, 1L,
                                                                                1L, 1L, 1L, 1L, 1L, 0L, 1L, 1L, 1L, 0L, 1L, 1L, 1L, 1L, 1L,
                                                                                1L, 1L, 1L, 1L, 1L, 1L, 1L, 0L, 0L, 1L, 0L, 1L, 0L, 0L, 1L,
                                                                                1L, 1L, 1L, 0L, 0L, 0L, 1L, 0L, 1L, 1L, 0L, 0L, 1L, 1L, 1L,
                                                                                1L, 1L, 1L, 1L, 1L, 1L, 0L, 1L, 1L, 1L, 0L)), class = "data.frame", row.names = c(NA,
                                                                                -707L))

df <- df[complete.cases(df),]
set.seed(1)
t <- round(0.7 * nrow(df))
train <- sample(nrow(df), t, replace = FALSE)
trainset <- df[train,]
testset  <- df[-train,]
m <- glm(y ~ x1 + x2, data = trainset, family="binomial")
predict(m, testset, type="response")

Answer: In case of few observations of a certain type, the best thing is always to gather additional data. If this is not possible you can rather discard these observations, or you can merge them into larger groups. So in your case, you could merge 'TL' and 'TR' to 'T' and conduct your analysis with that.
df$x1 = as.character(df$x1)
df$x1[df$x1=="TL"] = "T"
df$x1[df$x1=="TR"] = "T"

As you still have only five entries for this new category, this is however also not a satisfactory fix.
For logistic regression the concept of EPV (events per variable) is important.

'Events per variable (EPV) and the relative performance of different strategies for estimating the out-of-sample validity of logistic regression models.' Austin & Steierberg (2017)

This article states that 'Differences between the bootstrap-corrected approach and the use of an independent validation sample were minimal once the number of events per variable was at least 20'. In their experiment they therefore conclude that one should at least have 20 events per variable. You should take a look at the article.
Comment: Thanks, gathering more data isn't an option. And merging the two isn't a fix as there's still a very small amount (5 after merging). I then considered merging *further* into just `bottom / not-bottom` (as outlined in the OP) but was unsure about the validity of this approach. Perhaps in this instance it's best to just discard those levels (and use only bottom,middle values instead) as though they contained `NA` values or something instead. I'm not sure
Comment: I updated my answer but the problem is still the same. You have to few observations. Discarding might therefore really be an option.


Apache 2.4: Require IP does not work as expected

Question: I got the following configuration in my apache2.4 web server:
<FilesMatch "(^\.|wp-config\.php|xmlrpc\.php|(?<!robots)\.txt|(liesmich|readme)\.*)">
Require ip 22.214.171.124 126.96.36.199 188.8.131.52 126.96.36.199 188.8.131.52 184.108.40.206 220.127.116.11 220.127.116.11 18.104.22.168 126.96.36.199 220.127.116.11 126.96.36.199 18.104.22.168 220.127.116.11 184.108.40.206 18.104.22.168 18.104.22.168 22.214.171.124 18.104.22.168 220.127.116.11 22.214.171.124 220.127.116.11 184.108.40.206 18.104.22.168 22.214.171.124 188.8.131.52 220.127.116.11 18.104.22.168 188.8.131.52 184.108.40.206
</FilesMatch>

Well, if I call example.com/xmlrpc.php from a valid IP (e.g. 188.8.131.52), I'm still getting 401. What did I do wrong?
Comment: Typically your server log contains a hint as to why access was denied. Since you only include part of your configuration there may also be other [applicable sections of your configuration](http://httpd.apache.org/docs/2.4/sections.html#merging) or a `.htaccess` file in the path. The regex appears OK though.
Answer:
The robots rules is wrong, as any file .txt will match this regexp, even robots.txt.

So you need to change (?<!robots)\.txt by (!robots\.txt)

401 error mean you are not logged in. Here Require ip should trigger 403 error. That mean, to get access to those files, you need to be logged AND use an ip from the list.


Find the value of $\frac{4x}{y+1} + \frac{16y}{z+1} + \frac{64z}{x+1}$

Question:
Let $x,y,z$ be positive real numbers such that $x+y+z = 1$ and $xy+yz+zx = \frac{1}{3}$. Find the vlaue of $$\frac{4x}{y+1} + \frac{16y}{z+1} + \frac{64z}{x+1}.$$

So far using the fact that $(x+y+z)^2 = x^2+y^2+z^2 + 2(xy+yz+zx)$, I was able to get $x^2+y^2+z^2 = \frac{1}{3}$. Then I tried finding the common denominator of $\frac{4x}{y+1} + \frac{16y}{z+1} + \frac{64z}{x+1}$, which got very messy quickly and I think there's a nicer way to do this problem, but for now I am stuck.
Comment: Just a comment: there is no need to assume that $x,y,z>0$.  The three variables merely need to be real numbers.  The only $(x,y,z)\in\mathbb{R}^3$ satisfying $x+y+z=1$ and $xy+yz+zx=\frac13$ is $\left(\frac13,\frac13,\frac13\right)$.  Lord Shark the Unknown's proof verifies this claim.
Answer: The point is that $x=y=z=1/3$.
Too see this consider
$$0=(x+y+z)^2-3(xy+xz+yz)=\frac{(x-y)^2+(x-z)^2+(y-z)^2}{2}.$$


Questions related to open intervals and open sets

Question: Decide on the validity of the following conjectures
a) Continuous functions take bounded open intervals to bounded open intervals.
I can pick a counter example f(x) = tan(x) which is bounded -2 < x < 2 but f(x) is unbounded
b) Continuous functions take bounded open intervals to open sets.
For this question, what is the difference between open intervals and open sets?
Comment: There's a simple example of a continuous function which maps an open interval to a closed interval...
Comment: a flat line without two end points will do it right?
Comment: Yes, $f(x)=C$ also works.  I was thinking $f(x) = \sin x$: maps $(0,2\pi)$ to $[-1,1]$.
Answer: Open sets are arbitrary unions and finite intersection of open intervals. For example $(0,1)\cup (2,5)$ is an open set, but it is not an interval.
Comment: Also the unbounded sets written $(-\infty,x)$ and $(y,\infty)$.
Comment: is (0,1) U {5} an open set?
Comment: And by the way, the statement is not true.
Comment: No. ${5}$ has no neighbourhood $N$ around it such that $N$ is completely contained in $(0,1)\cup \{5\}$.
Comment: @aschepler 4 These cases are taken care of by the arbitrary unions.


Supremum and Infimum of functions

Question: I have been given the following homework problem... struggling. Any help would be appreciated.
With the following functions state;
a) State if the function is monotone.
1
b) Decide if it is injective, surjective or bijective on the given domain.
c)Find the Supremum and Infimum (if they exist); in each case state whether or not the function attains its bounds.
$$1.\ \ f(x)=\frac1{1+x^4}:\mathbb{R}\to(0,1]$$
$$2.\ \ f(x)=\tan x:(-\frac\pi2,\frac\pi2)\to\mathbb{R}$$
I understand;

Injective is one to one (does monotone check a similar thing?)
Supremum is the greatestlower bound of the set (given the constraints, $\mathbb{R}$/$\mathbb{N}$/$\mathbb{Z}$/etc)
Infimum is the lowest upper bound of the set (given the constraints, $\mathbb{R}$/$\mathbb{N}$/$\mathbb{Z}$/etc)

How do you apply these when you are given functions, rather than sets?
Comment: The supremum of a function is the supremum of its image. A function $f:D \to \mathbb R$ is said to attain its supremum if there exists $x \in D$ with $f(x) = \sup f(D)$. Since the supremum of an arbitrary subset $I \subseteq \mathbb R$, if exists, may not be in $I$, it is possible for a function $f$ to not attain the supremum (even when the supremum exists).
Comment: Do you know what the words monotone, injective, surjective, bijective, supremum, and infimum mean? If not, look up their definitions and if you still don't understand what some of them mean, feel free to ask a more specific question here. If you know what the words mean, but don't understand how to determine whether a function is monotone or not and so on, make sure to make that clear in your question. It is very hard to tackle the issues you're struggling with if you don't explicitly say what those issues are.
Answer: Pictures should significantly help with these questions.  Look at the pictures in this link of your first function.
Now, a function is monotonic, roughly, if it always increases or always decreases.  From the picture, we can see that $1/(1+x^4)$ is not monotonic.
Injective means that every $y$ value has one and only one $x$ value.  Notice that the $y$ value $1/2$ corresponds to the $x$ values $1$ and $-1$, so the function is not injective.  Another way to test this is to use the horizontal line test.
The function is surjective, because every $y$-value within $(0,1]$ is obtained.
The function cannot be bijective, because it has to be both injective and surjective, but it is not injective.
Finally, the supremum and infimum of a function are the least upper bound and greatest lower bound respectively.  Think of them as the $y$-values corresponding to the horizontal lines that enclose the entire graph.  In this case, it will be the horizontal lines $y=0$ and $y=1$, so the infimum is $0$ and the supremum is $1$.  $y=1$ actually intersects the function, so the supremum is obtained.  $y=0$ does not intersect the function, so the infimum is not obtained.
See if you can work with $\tan x$ on your own.

Supremum and Infimum of functions


determining the limit of an integral

Question: Let $f(x):\mathbb{R} \to \mathbb{R}$ be a continuous function, for every $n > 0$ define:
$$a_n = \int_{\frac{-1}{n}}^{\frac{1}{n}} f(x) \,dx$$
determine $\lim\limits_{n\to\infty} a_n$
At first glance it would seem like the limit approaches zero, is that statement true?
Answer: Of course it's true! Since $f$ is continuous, its absolute value assumes its maximum on, say, [-1, 1]. Let $M$ be that maximum. Then
$$
\left| \int_{-1/n}^{1/n} f(x) dx \right| \le \int_{-1/n}^{1/n} |f(x)| dx \le \frac{2M}{n}.
$$
Answer: Yes, the  limit is zero.
Hint:
if $F$ is an anti derivative of $f$,then $F$ is continuous at $0$.
Answer: Here's another proof.
We know that since $f$ is continuous we may apply the mean value theorem for integrals which guarantees for each of the given intervals $[-\frac{1}{n}, \frac{1}{n}]$ there is a number $c_n$ (depending upon $n$) such that
$$f(c_n)(\frac{1}{n}+\frac{1}{n})=\int_{-\frac{1}{n}}^\frac{1}{n} f(x)dx$$
The intervals $[-\frac{1}{n}, \frac{1}{n}]$ will shrink to the point $0$ in the limit (need to justify this by finite intersection property or something else but it's true)
so we see that the sequence $c_n\to 0$ as $n\to \infty$.
Again since $f$ is continuous $\lim_{n\to \infty} f(c_n)=f(\lim_{n\to \infty} c_n)=f(0)$
Therefore $\lim_{n\to \infty} \frac{2f(c_n)}{n}=0$ and we done.
Answer: Mean value theorem for integrals :
$a_n=f(t) \int_{-1/n}^{1/n}1dx=(2/n)f(t)$, where $t \in [-1/n,1/n]$.
$\lim_{n \rightarrow \infty}(2/n) f(t)=$
$\lim_{n \rightarrow \infty} (2/n)\lim_{n \rightarrow \infty} $f(t) =0f(0)=0;$
Used: $\lim_{n \rightarrow \infty} f(t) =0$, since
$t \rightarrow 0$, and $f$ is continuos.

determining the limit of an integral


how to open .clas file after adding extra code to actual java file

Question: class Demo
{
int i;
}

After compiling this Demo.java file i get Demo.class file which is added by extra code that having defalut contructor
class Demo extend Object
{
Demo(Demo this)
{
super(this);
}
}

when i am going to open .class file using textpad and other editor tools it's showing some other fonts. But compiler is adding some extra code into java file.
So how to see that compiled file which having extracode like this.
Comment: You don't have to view a `.class` file in an editor. Usually you _run_ a class file, if it is runnable (has [`main()` method](http://tutorials.jenkov.com/java/main-program.html)). Please keep reading your Java textbook.
Comment: use a decompiler to open .class file. It will not open in textpad.
Comment: If you can't properly format your code, don't bother with decompiling classes. Start from the basics, not from the middle.
Comment: use java file to read your content.. If you want to open some class that provided by the jdk or any external jar lib you have added,then use jad decompiler..But for your own file, use java file no need to open .class file
Answer: Use Java de-compiler to convert your class file to Java file again ..then you can see that
how compiler takes your code .
You can use simple commandline decompiler JAD JAD decompile download link
Answer: Use a class decompiler like jd-gui. It will decompile your class file.


OpenVPN client on Windows 7 - cannot add route from config script

Question: I am connecting from my Windows 7 laptop to an openvpn server and I am unable to automatically add a route.
In my script I have the line:
route-up "route add 192.168.33.0 mask 255.255.255.0 10.0.33.1"
but after the connection is set-up there is an error message:
Sat Feb 06 20:30:07 2010 us=974000 openvpn_execve: CreateProcess route failed: Cannot find file specified.   (errno=2)
Sat Feb 06 20:30:07 2010 us=989000 Route script failed: external program did not execute -- returned error code -1

The openvpn.exe is run as administrator.
Any ideas?
Answer: Ughh, finally found a solution (Windows-specific).
Put into OpenVPN client config the parameter:
script-security 2 system

The description from openvpn.net manual (https://community.openvpn.net/openvpn/wiki/Openvpn22ManPage) explains it:

--script-security level [method]
      This directive offers policy-level control over OpenVPN's usage of
  external programs and scripts. Lower
  level values are more restrictive,
  higher values are more permissive.
  Settings for level:
0 -- Strictly no calling of external programs.
1 -- (Default) Only call built-in executables such as ifconfig, ip, route, or netsh.
2 -- Allow calling of built-in executables and user-defined scripts.
3 -- Allow passwords to be passed to scripts via environmental variables
(potentially unsafe).

The method parameter indicates how OpenVPN should call external commands
  and scripts. Settings for method:
execve -- (default) Use execve() function on Unix family OSes and CreateProcess()
on Windows.
system -- Use system() function (deprecated and less safe since the external
program command line is subject to shell expansion).

The --script-security option was introduced in OpenVPN 2.1_rc9. For
  configuration file compatibility with
  previous OpenVPN versions, use:
  --script-security 3 system
Answer: better use:
route 192.168.33.0 255.255.255.0 10.0.33.1
this way route will be added and deleted when you connect and disconnect the vpn
Answer: You need to run your OpenVNP client with run as Administrator Command for it to work.
Comment: this was the first thing I have tested. Unsuccessfully.
Looks like the route command cannot be executed anyway.
I gave it 'Everyone' read/execute permission - no luck :(


Determine if the system is using dark mode in Laravel

Question: I have a laravel installation and have tailwind set to media for dark mode so it uses the systems preference.
How can I now determine if I'm using dark mode from a blade file? In particular I have 2 svg's one I want to use with dark mode and the other with light mode:
@if( [unknown logic] )
    [dark svg]
@else
    [light svg]
@endif

Also I might decide to use class instead of media in the tailwind config as I had implemented a toggle to switch modes. I set a $theme variable for this in my AppServiceProvider.php files boot function:
        view()->composer('layouts.app', function ($view) {
            $theme = \Cookie::get('theme');
            if ($theme != 'dark' && $theme != 'light') {
                $theme = 'light';
            }

            $view->with('theme', $theme);
        });

While this works for the most part it doesn't work until I'm logged in.
So how do I address this so I can switch the theme anywhere in my app using either media or class in my tailwind config?
I have tried to use the $theme value and also tried to get the cookie but i always get the light mode svg
Comment: Why not print both SVGs and display the correct one using CSS? Usually, the server can't determine whether you are using dark or light mode
Comment: Not really sure how I'd do that? I know I can use dark: prefix but not sure. Are you suggesting adding the svg in a css class say .logo and then using class="logo dark:logo {etc}" in the blade file? This would be two files with the svg in them right?
Comment: "This would be two files with the svg in them right?" - no, two divs, one to be shown, one to be hidden
Answer: You can use the media query of the tailwind to conditionally show which SVG you want to show, you can apply the classes directly into the SVG element if you wish as I have done it in the parent div.

    My SVG if theme is dark

    My SVG if theme is light

The server for the most part does not know about your theme. So let the browser (HTML, CSS, JS) handle the conditional rendering according to the theme and not PHP. But if you really want to send only one SVG element, see this question to get your preferred theme How do I detect dark mode using JavaScript?, and save it in a cookie or your database.
Hope this helps. Thank you.


Show that $f(x)$ is absolutely continuous in $[0,1]$, but not for $|f|^{1/2}(x)$.

Question: Let $f(x)=x^2\sin^2(\pi/x)$ for $x\in (0,1]$ and $f(0)=0$. Show that $f(x)$ is absolutely continuous in $[0,1]$, but $|f|^{1/2}(x)$ is not.
Attempt. Note that $f'(x)=2x\sin^2(\pi/x)-\pi\sin(2\pi/x)$ implies that $|f'(x)|\leq 2x+\pi$ for $x\in (0,1]$. So we have
$$\int_0^1|f'(x)|dx\leq \int_0^1 (2x+\pi)dx<\infty$$
Hence, $f$ is absolutely continuous.
For the second part, I claim that $x|\sin(\pi/x)|$ is not of bounded variation to conclude that it is not absolutely continuous. But, I couldn't prove it. In fact, I am able to prove that the function $x\sin(\pi/x)$ is not of bounded variation by using the sequence $x_n=\frac{2}{2n+1}$.
I would be glad if someone could help me and check my attempt. Thanks!
Comment: If $g$ is continuous and $|g|$ is of bounded variation, then $g$ is of bounded variation. See https://math.stackexchange.com/questions/2299679/f-is-of-bounded-variation-rightarrow-f-is-of-bounded-variation
Comment: you still need to show that $f(x)=\int_0^xf'(t)dt+f(0)$
Answer: Your estimate works to prove that the almost everywhere derivative is $L^1$, and your proof sketch is how I would prove the derivative is not BV and so not AC.
However, you still must show that the fundamental theorem of calculus holds. This is readily done using the usual calculus FTC though, indeed fix $\delta>0$. Then,
$$
x^2\sin^2(\pi/x)-\delta^2\sin^2(\pi/\delta)=\int_\delta^x f'(t)\mathrm dt=\int_0^xf'(t)\mathrm dt-\int_0^\delta f'(t)\mathrm dt
$$
Now taking $\delta\downarrow 0$,
$$
x^2\sin^2(\pi/x)=\int_0^xf'(t)\mathrm dt-\lim_{\delta\downarrow 0}\int_0^\delta f'(t)\mathrm dt
$$
but using your estimate,
$$
\left|\int_0^\delta f'(t)\mathrm dt \right|\leq \delta^2+\pi\delta\to 0
$$


@JsonProperty present but returning null

Question: I have an annotated Java 11 class that's using Fasterxml and it's returning null for one of the properties even though I can see the data  in the source JSON. Is there a reason that this annotation no longer works with jackson:2.12.0?
The property in question is capitalized in the source so it's capitalized in the annotation as well.
Source JSON
{
    "stringOne": "hello",
    "stringTwo": "world",
    "floatOne": 0.0,
    "NUM": 15   <-- always returns null
}

Log Statement
TestJson{stringOne='hello', stringTwo='world', floatOne=0.0, NUM=null}

Class
import com.fasterxml.jackson.annotation.JsonProperty;
import java.io.Serializable;

@JsonFormat(with = JsonFormat.Feature.ACCEPT_CASE_INSENSITIVE_PROPERTIES)
public class TestJson implements Serializable{

    protected String stringOne;
    protected String stringTwo;
    protected Float floatOne;
    protected Integer NUM;

    @JsonProperty("stringOne")
    public String getStringOne() {
        return stringOne;
    }

    public void setStringOne(String stringOne) {
        this.stringOne = stringOne;
    }

    @JsonProperty("stringTwo")
    public String getStringTwo() {
        return stringTwo;
    }

    public void setStringTwo(String stringTwo) {
        this.stringTwo = stringTwo;
    }

    @JsonProperty("floatOne")
    public Float getFloat() {
        return floatOne;
    }

    public void setFloat(Float floatOne) {
        this.floatOne = floatOne;
    }

//////// Returns null for every 'NUM' property
    @JsonProperty("NUM")
    public Integer getNum() {
        return NUM;
    }

    @JsonProperty("NUM")
    public void setNum(Integer NUM) {
        this.NUM= NUM;
    }

    @Override
    public String toString() {
        return "TestJson{" +
                "stringOne='" + stringOne + '\'' +
                ", stringTwo='" + stringTwo + '\'' +
                ", floatOne=" + floatOne +
                ", NUM=" + NUM+
                '}';
    }

}

EDIT
Adding the request used to retrieve/serialize the data as a TestJson object
ClientResponse<TestJson> response = null;
TestJson testJson = null;
logger.info(encodeForLog("apiUrl.getPath: " + apiUrl.getPath()));
logger.info("proxy:" + proxy);

try {
    response = proxy.getData(apiUrl.getPath());

    if (response.getStatus() == Response.Status.OK.getStatusCode()) {
        testJson = response.getEntity();

        return testJson;
    } else {
        throw new FailedException("HTTP failure");
    }
}
finally {
    if (response != null) {
        response.releaseConnection();
    }
}

Comment: Have you tried as mentioned in this answer https://stackoverflow.com/questions/55096204/ignore-json-attribute-cases-declared-with-jsonproperty-with-spring-resttemplate
Comment: I can't reproduce this. Please provide a [mcve].
Comment: How do you do your deserialization? Just ran this test and it outputs `TestJson{stringOne='hello', stringTwo='world', floatOne=0.0, NUM=15}`

`ObjectMapper objectMapper = new ObjectMapper(); System.out.println(objectMapper.readValue(str, TestJson.class));`
Comment: @UsmanAzhar the ACCEPT_CASE_INSENSITIVE_PROPERTIES annotation is currently present at the class level
Comment: @Migwel I've added the request code. The legacy code uses deprecated `ClientResponse`
Comment: This is not a [mre]. If it is just a problem with Jackson, make a simple runnable main method with an ObjectMapper and test the serialization.
Answer: Set @JsonProperty on setter method.
@JsonProperty("NUM")
public Integer getNum() {
    return num;
}

@JsonProperty("NUM")
public void setNum(Integer num) {
    this.num = num;
}

Marker annotation that can be used to define a non-static method as a
"setter" or "getter" for a logical property (depending on its signature), or non-static object field to be used (serialized, deserialized) as a logical property.
https://fasterxml.github.io/jackson-annotations/javadoc/2.8/com/fasterxml/jackson/annotation/JsonProperty.html

Jackson version doesn't matter:

https://fasterxml.github.io/jackson-annotations/javadoc/2.12/com/fasterxml/jackson/annotation/JsonProperty.html

Tested with this class (Jackson 2.11.4):
@JsonFormat(with = JsonFormat.Feature.ACCEPT_CASE_INSENSITIVE_PROPERTIES)
public class TestJson implements Serializable {

    protected String stringOne;
    protected String stringTwo;
    protected Float floatOne;
    protected Integer num;

    @JsonProperty("stringOne")
    public String getStringOne() {
        return stringOne;
    }

    public void setStringOne(String stringOne) {
        this.stringOne = stringOne;
    }

    @JsonProperty("stringTwo")
    public String getStringTwo() {
        return stringTwo;
    }

    public void setStringTwo(String stringTwo) {
        this.stringTwo = stringTwo;
    }

    @JsonProperty("floatOne")
    public Float getFloat() {
        return floatOne;
    }

    public void setFloat(Float floatOne) {
        this.floatOne = floatOne;
    }

    //////// Returns null for every 'NUM' property
    @JsonProperty("NUM")
    public Integer getNum() {
        return num;
    }

    @JsonProperty("NUM")
    public void setNum(Integer num) {
        this.num= num;
    }

    @Override
    public String toString() {
        return "TestJson{" +
                "stringOne='" + stringOne + '\'' +
                ", stringTwo='" + stringTwo + '\'' +
                ", floatOne=" + floatOne +
                ", NUM=" + num+
                '}';
    }

}

Output:

and a better solution for TestJson:
public class TestJson implements Serializable {

    protected String stringOne;
    protected String stringTwo;
    protected Float floatOne;
    protected Integer num;

    @JsonCreator
    public TestJson(@JsonProperty("stringOne") String stringOne
            ,@JsonProperty("stringTwo") String stringTwo
            ,@JsonProperty("floatOne") Float floatOne
            ,@JsonProperty("NUM") Integer num) {
        this.stringOne = stringOne;
        this.stringTwo = stringTwo;
        this.floatOne = floatOne;
        this.num = num;
    }

    public String getStringOne() {
        return stringOne;
    }

    public void setStringOne(String stringOne) {
        this.stringOne = stringOne;
    }

    public String getStringTwo() {
        return stringTwo;
    }

    public void setStringTwo(String stringTwo) {
        this.stringTwo = stringTwo;
    }

    public Float getFloat() {
        return floatOne;
    }

    public void setFloat(Float floatOne) {
        this.floatOne = floatOne;
    }

    public Integer getNum() {
        return num;
    }

    public void setNum(Integer num) {
        this.num= num;
    }

    @Override
    public String toString() {
        return "TestJson{" +
                "stringOne='" + stringOne + '\'' +
                ", stringTwo='" + stringTwo + '\'' +
                ", floatOne=" + floatOne +
                ", NUM=" + num+
                '}';
    }

}

Comment: Why wouldn't the other fields fail as well if this were the case?
Comment: Because the field names match the json keys.
Comment: Check the fields name. if you change num field to NUM everything will be ok.
Comment: Perhaps,you have a problem in object mapping.Reference to @Migwel comment.


Pairwise comparisons after significant interaction results: parametric or non?

Question: I've run a 2-way ANOVA on growth rate data (grams/day) with the factors of year type (good and poor) and site (A and B). Though the data themselves are non-normal and do not have homogeneous variances, the residuals fall pretty nicely along the qq plot, and they are not heteroskedastic. Running the test shows that there is an interaction between year-type and site. It's been suggested to me that I now must run a series of pairwise comparisons to look for differences because of this interaction effect, which I assumed I'd need to do anyway.
My stats program (Sigmaplot11, which includes the SigmaStat package) automatically does post-hoc tests for any significant results (in this case is reports: "All Pairwise Multiple Comparison Procedures (Holm-Sidak method): Overall significance level = 0.05). I assume that this is the correct way to conduct the pairwise comparisons rather than making them separately?
Here's why I ask: Using these built-in post-hoc tests, I get significant results in both good years and poor (p<0.001 in each case). However, doing these tests separately (good vs. good and poor vs. poor) as Mann-Whitney rank sum tests (the raw data are non-normal with heterogeneous variances), I get no significant difference between sites within poor years. t-tests show the same as the ANOVA. I assume this is because I'm not comparing means in the case of the Mann-Whitney, but which post-hoc method should I be using in this case?!
EDIT: following @whuber's informative comment, I've taken a look at my other 2-way ANOVAs run in a similar manner. I've done another similar test today comparing adult weight. The t-test from the multiple pairwise comparisons after the 2-way ANOVA shows no difference (t=1.547, p=0.122), but a t-test run outside of the ANOVA shows highly significant difference (t=-4.739, p<0.001). As @chl pointed out, I would expect these 2 t-tests to have the same t-values; note that these 2 tests use exactly the same original data. Any idea why this might be or how I can interpret this?
Thanks for any suggestions you can provide!!
EDIT #2: Just to update anyone who's interested, I've taken a look more closely at the numbers behind the test, and it looks like somehow the software is not doing what I'm asking. It lists a table called the Least Square Means, listing each site, its mean and its standard error of the mean. The overall site means listed in this table are not correct. However, for each site within year type, it does have the correct means in the Least Square Means table. I'm giving up on the main factor of site comparison within this test, and sticking to the t-value given in the t-test for this main factor comparison. I'm still not sure what's going on exactly, but from comments and answers provided (thanks again!), I feel that this is a safe move, and I must move on with other things.
Thanks for all of your help!
Comment: The M-W tests fail to identify significant differences because the site-to-site variability in each of the groups masks the year type effect.  The appropriate analog of the M-W to run is the Kruskal-Wallis test with *four* groups identified by site and year type.  However, because your residuals look homoscedastic and normal, there is no need to do this at all.
Comment: @whuber Thanks! Just to make sure I follow you correctly: because my residuals look ok, I can stick with the 2-way ANOVA post-hocs (the Holm-Sidak-corrected t-tests) that my software provides?
Answer: If I understand your question correctly, you are wondering why you got different p-values from your t-tests when they are carried out as post-hoc tests or as separate tests. But did you control the FWER in the second case (because this is what id done with the step down Sidak-Holm method)? Because, in case of simple t-tests, the t-values won't change, unless you use a different pooling method for computing variance at the denominator, but the p-value of the unprotected tests will be lower than the corrected one.
This is easily seen with Bonferroni adjustment, since we multiply the observed p-value by the number of tests. With step-down methods like Holm-Sidak, the idea is rather to sort the null hypothesis tests by increasing p-values and correct the alpha value with Sidak correction factor in a stepwise manner ($\alpha' = 1 - (1 - \alpha)^k$, with $k$ the number of possible comparisons, updated after each step). Note that, in contrast to Bonferroni-Holm's method, control of the FWER is only guaranteed when comparisons are independent. A more detailed description of the different kind of correction for multiple comparisons is available here: Pairwise Comparisons in SAS and SPSS.
Comment: thanks for the excellent response. I'm aware of the FWER problem, and intended on using the Holm-Bonferroni method for FWER outside of the automatic tests (easy to do, well-explained in Wikipedia), but here's the rub: using exactly the same data, my t-values are different (edited in the question). Any idea why that might be? Or how to interpret that? I'm guessing it's something to do with the way the software handles the tests, but it seems to me that the way I've done it should leave these 2 test results identical (wrt the t-value).
Thanks again!!


$x \in A \notin B$

Question: Suppose I wanted to say that
$$x \in A \notin B$$.
Is there a (better) standard way to describe this? Else, I'll go for my original formulation:
$$ \ldots \text{where}\, x \in A\,\text{ but not in } B$$
Comment: You could write $x \in A$, $x \notin B$. That's just a few symbols more...
Comment: Writing it in words is almost always so much clearer... To make it even better, try "where $x$ is in $A$ but not in $B$".
Answer: What you want is $x\in A\setminus B$: the set $A\setminus B$ is by definition the set of things that are in $A$ but not in $B$. (An older notation is $A-B$; I don't recommend it.)
The expression $x\in A\notin B$ says something entirely different: it says that $x$ is an element of $A$, and $A$ is not an element of $B$.
Answer: Your statement can be written with the set-minus character: $\setminus$
(For typesetting in LaTeX, for example, on math.se: use <code>\setminus</code>):
$$x \in A\setminus B,$$ which is defined to be exactly:
$$x \in A \land x \notin B$$
While you can chain together set inclusion $\subset$, e.g. $x \in A \subset B \subset C$ from which it follows that  $x \in A \land x\in B \land x\in C$, that's not appropriate for set membership:
$$x \in A \notin B \not\equiv x \in A \land x \notin B.$$
Comment: So, you suggested \setminus rather than -? +)
Answer: Next formula describes your relation
$A \ni x \notin B$
Comment: Some might argue that you are prefacing a statement about A, with asserting "A such that x is not in B" which might be confusing. There was just yesterday a "debate" about the notation $\ni$ and its signification: "such that..." vs. reversed set-inclusion (the correlate of $\supset$), etc. Anyway, +1 for the creativity!
Comment: $\ni$ does not appear to be in that table. Even if it were, it is still a confusing notation since many people use $\ni$ and/or $\backepsilon$ to mean "such that". A more common notation would be $x\in A\setminus B$ or $x\in A-B$
Comment: @robjohn Wiki was about "such that". It may be expressed as ":" or "|". If some people use $\ni$ as "such that" they do it wrong. There is nothing in use two relations in one expression instead of two expressions. Like $1<x<2$. But yes, $x \in A \backslash B$ is more clear to understand.
Comment: Potentially, $\ni$ for reverse inclusion could be useful. For instance, if you want to sum over all sets $A$ containing $x$, you could write $\sum_{A \ni x} f(A)$. But I have to agree that $A \ni x \notin B$ is ugly...
Comment: Just look at the LaTeX notation to clarify the meaning of $\ni$.

[Wiki](http://en.wikipedia.org/wiki/List_of_mathematical_symbols)
Comment: @Sergei...I agree...just mentioning that some want if for "such that"...
Comment: Just because that page does not list $\ni$ for "such that", does not mean it is not used as such. However, it is definitely uncommon to see a symbol and its reverse in an inequality or inclusion. For example, I don't think I have ever seen $x\gt y\lt z$.

$x \in A \notin B$


Generic way of slicing on time in Pandas from beginning of Series to date

Question: I have a bunch of tipping bucket raingauge data that I need to calibrate which have multiple calibration factors for different time periods. I've been going about this like:
data = pd.Series(range(100), pd.date_range('1950-01-01', freq='d', periods=100))

data.ix[:'2000-01-01'] *= CF1
data.ix['2000-01-02':'2000-05-12'] *= CF2
.
.
.
data.ix['2015-02-23':] *= CFn

For each station that I'm working with. I want to be able to apply these using a dictionary like so:
calibrations = {"Station1": [(slice(None), '2000-01-01', CF1),
                             ('2000-01-02', '2000-05-12', CF2),
                             ...]}

for station in calibrations:
    for start,end,cf in calibrations[station]:
        data.ix[start:end, station] *= cf

Which would be a lot more concise and easy to maintain by keeping the calibration information in a dict or csv file that can be imported.
How can I slice a Series with a DatetimeIndex in a generic way that accounts for the beginning and end time periods instead of having to do data.ix[:timestamp] and data.ix[timestamp:] for the beginning and ends of the data?
I've tried data.ix[slice(None):timestamp] for the beginning of the record but a pandas Timestamp or convertable string is required.
Hopefully this makes sense any help would be appreciated.
Comment: I just found the `truncate` method which will definitely work for this... Any other approaches are welcome.
Answer: You could try looking into the lambda function... or create a column from the index (taken from another post):
Series(s.reset_index().apply(f, axis=1).values, index=s.index)

Or the 'where' function.
I need to investigate this further for you (an interesting problem).
Comment: There doesn't seem to be a lamda method for Series or DataFrame or lambda function at the top level of Pandas. Can you be more specific?
Comment: Thanks for this. I found out that to do what I've mentioned I needed to replace   `slice(None)` with simply `None`
Answer: For future reference I resolved my issue by replacing slice(None) with None
which allows me to use the same .ix[start:end] syntax to represent the beginning or end of the series by using None instead of a string denoting the first our last timestamp.


jQuery change href when image slider changes

Question: I have a working image slider that uses jQuery to change the image (yes, I know using background images in DIVs is not the best practice, but it's the only method that works with the rest of my page):
My HTML:

jQuery:
var urls = [ 'http://www.google.com','http://www.microsoft.com','http://www.yahoo.com' ];
var images = [ 'http://www.placehold.it/2000x500/ff0000.png','http://www.placehold.it/2000x500/00ff00.png','http://www.placehold.it/2000x500/0000ff.png' ];
var cur_image = 0;
function changeBackground() {
    cur_image++;
    if ( cur_image >= images.length )
        cur_image = 0;

    // change images
    $( '.featuredImages' ).css({
        backgroundImage: 'url(' + images[ cur_image ] + ')'
    });
    $( '.featuredImages .slide' ).fadeOut( 3000, function(){
        $( this ).css({
            backgroundImage: 'url(' + images[ cur_image ] + ')'
        }).show();
    } );

}

setInterval( changeBackground, 10000 );

And CSS:
.featuredImages {
    position:absolute;
    margin: 0;
    height: 500px;
    width: 100%;
    background: transparent url('') no-repeat center;
    overflow: hidden;
}
.featuredImages .slide {
    position: absolute;
    margin: 0;
    height: 500px;
    width: 100%;
    background: transparent url('') no-repeat center;
    overflow: hidden;
}

http://jsfiddle.net/hnS9U/1/
I would like to change the href of that anchor tag ("featuredLinks") when the image swaps so that it links to the page that the images relates to.
I would like to use an array to store the links ("urls") and the same loop counter that is used for the images to keep track of what link to use.
Any pointers in the right direction would be great!
Thanks in advance!
Answer: Basically, hrefs are no more than attributes of the a element. All you need to do is change the value of that attribute. As for the array, if you are planning to use two arrays and you are planning to have the indexes of each correspond to their counterparts in the other array, then you can use the same indexer, cur_image, for the hrefs, as well.
Have you tried:
$("#featuredLink").attr("href", "hrefOfNewImage");

In your case, this would be more like:
$("#featuredLink").attr("href", urls[cur_image]);

In your function, this would look like:
function changeBackground() {
    cur_image++;
    if ( cur_image >= images.length )
        cur_image = 0;

    // change link
    $("#featuredLink").attr("href", urls[cur_image]);

    // change images
    $( '.featuredImages' ).css({
        backgroundImage: 'url(' + images[ cur_image ] + ')'
    });
    $( '.featuredImages .slide' ).fadeOut( 3000, function(){
        $( this ).css({
            backgroundImage: 'url(' + images[ cur_image ] + ')'
        }).show();
    } );

};

Let me know if you have any more questions. Good luck! :)
Comment: Thank you very much! That works great! If the cursor is already on the image the href does not change until the cursor is taken off the image and placed back on. Is that a cause of the browser or something that can be corrected with jQuery? Example: http://jsfiddle.net/hnS9U/2/
Comment: Thanks for the quick answer, but I'm pretty new to JS. Would you mind showing me how to add this to the code I provided? Thank you!
Comment: Done! If the rest of your code is working then that should work right away.
Comment: The URL should change, but the little popup that reads you the URL might not That's a browser thing.
Answer: You can add this code in changeBackground():
$('#featuredLink').attr("href", urls[cur_image]);

I used cur_image but you can create another var!
Your HTML semantical is bad bad bad... A div inside a link isn't semantical, try change to span.


Get UserName and Password in WinRT?

Question: I have created a sample application in Windows 8 I need username and password of logged in user of Windows to authenticate him/ her in the application. I know that we can use Environment.CurrentUser in Old desktop application how can i get User Info for authentication purpose in Windows 8 Metro Application?
Comment: I have looked into that but it doesn't given me login id for the user its gives me just the user name.
Answer: You can get the current user name but never the password.
To make your scenario work your app needs to select the enterpriseAuthentication capability and then you should be able to use CredentialCache.DefaultNetworkCredentials from within your app

Get UserName and Password in WinRT?


Dúvida sobre query (agrupamento)

Question: Tenho uma tabela chamada ALUNO_LEGADO no SGBD SQL Server conforme abaixo:

Supondo que existam apenas 5 disciplinas (1,2,3,4,5) e os conceitos sejam A = Aprovado e R = Reprovado, qual condição utilizo para buscar apenas os RA's que possuam reprovação em todas as 5 disciplinas?
Answer: Assumindo a seguinte estrutura
create table aluno_legado
(
   ra          varchar(03),
   disciplina  int,
   conceito    varchar(01)
);

insert into aluno_legado(ra, disciplina, conceito) values
('ra1', 1, 'R'),
('ra1', 2, 'R'),
('ra1', 3, 'R'),
('ra1', 4, 'R'),
('ra1', 5, 'R'),
('ra2', 1, 'R'),
('ra2', 2, 'R'),
('ra2', 3, 'R'),
('ra2', 4, 'R'),
('ra2', 5, 'A'),
('ra3', 1, 'R'),
('ra3', 2, 'R'),
('ra3', 3, 'R'),
('ra3', 4, 'R');

Supondo que existem apenas 5 disciplinas, a seguinte query irá produzir o resultado que pretendes
select ra
from   aluno_legado
group by ra
having count(distinct case when conceito = 'R' then disciplina end) = 5;

Esta query devolve os RA que têm o número de disciplinas únicas/distintas com conceito = 'R' igual a 5.
Vê o SQLFiddle
Comment: Obrigado Bruno, funcionou

Dúvida sobre query (agrupamento)


Revert views missing. Any workarounds?

Question: In Drupal 8 reverting views to their original (in the core, custom or contributed module) became difficult. Supposedly the module config_update would allow reverting a view, but that promises to be a more laborious than simply clicking a link like we were used to in Drupal 7.
I was wondering if it would be possible to make selected views read-only? That way administrators with Views UI permission would have no edit link forcing them to work with a duplicate.
Hints on how to accomplish this? Any other possible workarounds?
Answer: A simple workaround without an additional module would be to copy and paste the content of the yaml file views.view.[view-id].yml you find in the module's /config/optional folder to www.mysite.com/admin/config/development/configuration/single/import.
Select the configuration type "View" and add the first line containing the UUID from the active configuration (switch to Export - Single item).
If you have to do this on a regular basis then the recommend way is to manage the configuration with Git, see this tutorial Using Configuration Management and Git to Track Drupal 8 Configuration.

Revert views missing. Any workarounds?


login function rendering first letter only

Question: I have just made the login function and it is working alright;
however the name is not shows correctly; for some reason it only echoes the first letter of the name, J. instead if Jack:
It is written alright in the database.
echo "You are now logged in , {$_SESSION['name']}";

Has anyone ever encountered the same problem?
Regards
Jacek
Answer: echo "You are now logged in , {$_SESSION[name]}";

Don't use quotes around name. They are not necessary inside a double quoted string to access an array element.
Comment: any other suggestions?
Comment: what is the result of `var_dump($_SESSION["name"])`?
Comment: i've already figured it out; changed my code and now it's working alright. Thanks for your suggestions anyway.
Answer: just thought i might add more code to make the problem a bit more clear:
here the function check_login checks if the result is in the database and passes it on to another file:
function check_login($db, $email = '', $pass='')
{
if(!empty($_POST['email']) && !empty($_POST['pass']))
{
$sql="SELECT * FROM users WHERE email='$email' AND password='$pass'";
$r=$db->query($sql);
$num=$r->num_rows;
if($num != 0)
{
$row=$r->fetch_assoc();
return array (true, $row['name']);

 }
else
{
    echo "Your login details are incorrect. Please try again.";
}

}
}

In another file:
list($check,$data) = check_login($db, $_POST['email'], $_POST['pass']);

if($check)
{
session_start();
$_SESSION['user_id'] = $data['user_id'];
$_SESSION['name'] = $data['name'];
redirect_user('the_stoles/loggedin.php');
}
else
{
    echo "Your login details are incorrect. Please try again.";
}

ane finally:
session_start();
                if(!isset($_SESSION['user_id']))
                {
                    require('login_functions.php');
                    redirect_user();
                }
                else
                {
                echo "You are now logged in, {$_SESSION['name']}";
                }

I hope i made it a bit clearer and someone might get a clue.
Cheers in advance
Jacek


Overriding system.site.uuid with an environment variable

Question: I have a need to have separate sites behave as if they are clones of each other; that is, they each need to have the same site UUID.
Due to the environment I am operating in, I am unable to change the site UUID via drush config:edit once the site is installed as I have no SSH access to the environment. Likewise, the only way I can create a new site in this environment is to upload the files, create an empty database and then run the install script. This creates a new site, with a new UUID, and therefore is no longer a clone. Once sites are installed in the environment, my only way of interacting with them is through the administration UI.
Any site I create in this environment will have the same code base; it is not a matter of messing things up by importing the wrong config.
I can import the same database  into the new site once it is installed using Backup and Migrate, thereby changing the UUID (I assume). However, this does not quite solve the problem because it may be the case that I need to create sites via scripts in our continuous integration system.
My initial solution is to add a line in settings.php to override the configuration item in question, ie:
$config['system.site']['uuid'] = 'this is the site uuid';
However, when I export the configuration, the override value is not respected and configuration is exported using the original value. I can test this by exporting the configuration from a clone and trying to import it. If the UUID was being overridden 'fully', then I would expect the configuration import to fail.
Ideally, I would like to set the site UUID through an environment variable or service, so any site with access to the variable or service would be able to use the same UUID, and therefore be considered clones.
Has anyone had any success with something similar?
Comment: Once you have a running website, the uuid is basically baked into ALL config. Changing it in settings.php won't help you. The whole premise of single uuid-clones is plain wrong. The only solution to have the same config for different uuids is to export the config (drush cex), then via script delete the _config(i think) array and uuids from all the exported files. Then spin up a new site from clean sql file, set uuid via the settings.php and import config which will be treated like new(since no uuids). but event then you'll have issues(from that clean sql) so overall, bad idea from get go.
Comment: @IvanJaros this is simply not true. You can very easily update the site UUID using `drush cset system.site uuid "[new uuid]"`. Obviously this requires access to drush on the site in question. My problem was that I didn't have access to drush on the site, however some excellent work by the team in cloud.gov.au has sorted this issue out.
Comment: of course you can change the uuid, i didn't not say otherwise. try drush cex and you will see each config now has _core value which is based on the initial uuid and will make the config compatible only with site with that uuid.
Answer: In the end, it was a matter of getting Drush to work on the remote environment.
I was also able to build a small module to update the site UUID of an existing site, however we didn't end up using it. The code for that is available at this repository.
Essentially, this boils down to running something like this:
\Drupal::configFactory()
    ->getEditable('system.site')
    ->set('uuid', $uuid)
    ->save(TRUE);

Where $uuid is whatever the UUID you want, whether this is generated manually or loaded from a service.


Regular expression to search only websites names from random text

Question: I want to create a regular expression that search and return only website names from a text.
e.g.
"Hello, the total description of deals are below:
mango: maangobar22.com
Total Deals : 0
apple: myapplesite22.com
Total Deals : 3
berrymine22.com
Total Deals : 0
We hope to hear from you soon"
I want to search all websites name and store them in different variable.
I created the following re but since I am new to RE, I am unable to think where to start.
import re
import sys

text = "Hello, the total description of deals are below: mango: maangobar22.com Total Deals : 0 apple: myapplesite22.com Total Deals : 3 berrymine22.com Total Deals : 0 We hope to hear from you soon"

num = re.match(r'+..com', "", text)
print('Phone Num : ', text)
a1 = num.group()
a2 = num.group(1)
a1 = num.group(2)
a2 = num.group(3)

Any help is highly appreciated.
Comment: My 2-cents, just look it up in http://regexlib.com/Search.aspx?k=url&c=-1&m=-1&ps=20
Answer: You could use the following for your example:
import re
websites = re.findall(r'(\S+[.]com)', text)
# ['maangobar22.com', 'myapplesite22.com', 'berrymine22.com']

Comment: but what about urls that don't end in '.com'?
Comment: @ClydeByrdIII Err, then add more TLDs ?


How do I use `NestedArray::getValue()` to get a value from an array?

Question: I see the NestedArray::getValue() but the documentation isn't clear. How do I use this to get a value out of a nested array, such as form state or raw form input?
Answer: If you have an array like this:
$my_array = [
  'key1' => [
    'key1.1' => 'a',
    'key1.2' => 'b',
    'key1.3' => 'c',
  ],
  'key2' => [
    'key2.1' => 'x',
    'key2.2' => 'y',
    'key2.3' => 'z',
  ],
];

And you want to get to $my_array['key2']['key2.2'] dynamically (e.g., using an array of #parents from a form element), you can use NestedArray::getValue($my_array, ['key2', 'key2.2']).
As a bonus, this method returns a reference to the value so you can also change what you get back and the change will be reflected in the array.


How To Automatically Update Sharepoint List With Email Sent Date

Question: In a SharePoint site I keep a list of various projects for workflow management.  For each project periodic MS outlook emails are sent containing standard data and formatting.  Currently, when an email is sent someone has to manually key in the sent date in the list for the applicable project.  Is there a way when an email is sent to have the project in the SharePoint list automatically updated with the sent date? We would prefer that the email and attachments not be retained within the SharePoint site.  Specifics or links to specifics on how to accomplish this would be appreciated. thank you.
Answer: Assuming your are able to deploy a custom event handler to your SharePoint site a solution for your problem might look like this:

Create and email-enable a document library on the same SharePoint web
Send a carbon copy of the periodic email to this library
Create and register a custom event handler that gets called when an email is send to the email-enabled document library (see 'Creating a SharePoint Event Handler' on MSDN)
When the event handler gets called it inspects the subject or content of the email to identify the project list item in the project list
Set the 'Email sent' date of that project list item
Delete the email from the email-enabled document library within the event handler

Hope this helps.


How to know what events will trigger when doing specific operation in VIM?

Question: I am studying VIM events, but I found some events may not working well like ##TabLeave won't be triggered when using gt/gT to switch between tabpages. What can I do to know what event has been triggered by VIM when I am doing a specific operation, like typing tabmove command to execute it? I am writing a plugin to make my VIM tabpage can source back to previously visited tabpage, but the problem is tabmove command won't trigger anything, anyone can help me on this?
function! catchSomeEventTriggerByTabmCmd()
let histCmd = histget('cmd', -1)
if match(histCmd, '^tabm') == 0
DoUpdateJumpQueue()
endif
endfunction

Comment: https://vim.fandom.com/wiki/Debugging_window_autocommands
Comment: Hi Matt, thanks for sharing this link, this helped a lot!
Answer:
... I found some events may not working well like ##TabLeave won't be triggered when using 'gt/gT' to switch between tabpages.

gt/gT does trigger TabLeave. example:
:let g:foo = 1
:autocmd TabLeave * let g:foo = g:foo + 1 | echom "TabLeave Event " . g:foo
:tabnew

Now do a few gt/gT's. You should get messages

What can I do to know what event has been triggered by VIM when I am doing a specific operation, like typing 'tabmove' command to execute it? I am writing a plugin to make my VIM tabpage can source back to previously visited tabpage, but the problem is 'tabmove' command won't trigger anything, anyone can help me on this?

I am not sure you can use an event/autocmd like TabLeave to capture anything from :tabmove. It probably is also going to be tricky to use tab page numbers as well, since :tabmove modifies them.
Luckily, Vim always has to focus a window, so instead of trying to have a history of tab pages, maybe have a history have window id's. You may be able to use win_getid() and win_gotoid() to accomplish your history behavior.
For more help see:
:h win_getid()
:h win_gotoid()
:h windowid

Comment: Hi Peter, thanks sincerely for your answer, yes, I was wrong, the gt/gT does trigger the event #TabLeave. and I have figured out a way to track the tabmove command even it didn't trigger any tabpage related event. My way is to store the tabpage number by predefined function tabpagenr() when the #TabEnter event comes, and then compare it with the tabpage number when #TabLeave event, because when switching tabpages, these 2 number should always stay the same, but if there is a tabmove command between, then it's not. So basically, according to this point, then we can know it. Thanks anyway!


[XXX retainCount]==0 really represent memory released?

Question: all
when i use [nsmutablearray removeAllObjects]
i got :
      [nsmutableArray retainCount]==1;
then,i use [nsmutableArray relese];
i got [nsmutableArray retainCount]==1;
so ,i think ,is [XXX retainCount]==0 really represent memory released???
Answer: From the official docs:

Important: Typically there should be
  no reason to explicitly ask an object
  what its retain count is (see
  retainCount). The result is often
  misleading, as you may be unaware of
  what framework objects have retained
  an object in which you are interested.
  In debugging memory management issues,
  you should be concerned only with
  ensuring that your code adheres to the
  ownership rules.
Answer: retainCount can never return 0.


Compact: if seq has subseq that converges. But why is "seq converges" not enough?

Question: Compact: if seq has subseq that converges. But why is "seq converges" not enough?
Particular confusion:
-Sequence converges can be demonstrateable. So why does one need to investigate subsequences?
-Sequence having convergent subsequence is definition of sequentially compact (which is not same as compact).
Still my notes defined:
Set $K$ is compact if every sequence in $K$ has a convergent subsequence.
Is this an unclear definition?
Does one really require convergent subsequences in order to have compactness (not sequential compactness)?
Answer: It is obvious that two point $Y:=\{x,y\}$ in a topological space $X$ must be seq. compact.
If you define seq compact as 'each sequence must be convergent' you have that $Y$ is not seq. compact.
For example $a_{2n}:=x$ and $a_{2n-1}:=y$ is not convergent.


Algorithm to determine if a Diophantine Equation has an infinite number of solutions

Question: In their paper , Marker and Slaman, proved the decidability of the the theory of the natural numbers with the quantifier "for all but finitely many", One can obviously encode the question of whether any diophantine equation has an infinite number of solution as the question of whether a statement belonging to this language is satisfied by the Naturals or not. Since they proved the theory is decidable we know that such algorithm exists. My question is: Has any one tried to come up with an efficient algorithm for that ?
Link to the paper: http://www.math.uic.edu/~marker/aa-v3.pdf
Comment: The proof of decidability shows that the theory is the same as the corresponding theory of the reals. So the algorithms for deciding sentences about the field of real numbers will also work for the naturals in this language. That gives an upper bound, at least.
Comment: That sounds like an answer to me, Carl (or at any rate, more than just a comment).
Answer: The question of whether a diophantine equation has infinitely many solutions is at least hard as the question of whether a diophantine equation has any solutions, and is therefore undecidable. (As JDH comments below, in a certain technical sense, the question of whether there are infinitely many solutions may be harder.)
Proof: Let $F(x_1, x_2, \ldots, x_m)=0$ be any diophantine equation. Then $F=0$ has a solution if and only if $F(x_1, x_2, \ldots, x_{m-1}, y-z)=0$ has infinitely many solutions.
Your error is equating "infinitely many" with the much larger "all but finitely many".
UPDATE: As Mohammed points out "It is false that all but finitely many bagels are delicious" is equivalent to "infinitely many bagels are not delicious". And the theorem of Marker and Slaman is for all first order statements, not just for diophantine equations, so we should be able to use this rewording.
On skimming their paper, the first thing that I notice is that they have the quantifier $\forall^{\infty}$ ranging over a single integer variable, not over a $k$-tuple of integers, so you can say "For all but finitely many $x$, the following holds for all but finitely many $y$..." but can't directly say the stronger "For all but finitely many ordered pairs $(x,y)$..." But I'm not sure whether this is the heart of the difference, or just a minor technical issue.
Comment: David, you claim that the infinite-solution problem is "as hard as" the solution problem for diophantine equations, and this suffices to answer the question, but it would be more correct to say that it is "at least as hard as," since in fact it is strictly harder. The problem of determining whether a diophantine equation has a integer solution has complexity $\Sigma^0_1$---it is computably enumerable---but the problem of determining in general whether a diophantine equation has infinitely many solutions has complexity $\Pi^0_2$; indeed, it is $\Pi^0_2$-complete, hence strictly harder.
Comment: But aren't both quantifiers dual? For example consider the statement $\neg \forall^{\infty} \neg F = 0$, where $\forall^{\infty}$ is the quantifier "for all but finitely many", doesnt this statement mean there is an infinite number of solutions?
Comment: (I removed my comment and posted it as an answer.)
Answer: There is a fundamental error in this question.
For a one-variable diophantine equation, the question whether it has infinitely many solutions is rather trivial to answer (and the answer is the same over $\mathbb{Z}$ and over $\mathbb{R}$, as Carl pointed out).
The situation is different with more than one variables. The basic reason for this is that $$\exists^\infty x \exists^\infty y \cdots$$ does not mean

There are infinitely many pairs $x, y$ such that $\cdots$

It rather means,

There are infinitely many $x$ for each of which there are infinitely many $y$ such that $\cdots$

In fact, it is not possible to say there are infinitely many pairs (triples, quadruples, etc.) in the fragment of first-order logic that Marker and Slaman consider in their paper (for the reason that David pointed out).
Comment: @Charles: Without $\exists$ and $\forall$ you don't even have bounded quantifiers, so it would take some serious effort to get most primitive recursive functions in this context.
Comment: Exponentials are a distraction, you can encode ordered pairs as "$x$ and $y$ are positive and $w = x + (x+y)(x+y+1)/2$." The trouble is that you don't have $\exists$. So you want to say "$\exists^{\infty} w \exists x \exists y : w = x + (x+y)(x+y+1)/2$ and ...", but you can't ask for $x$ and $y$ to exist.
Comment: What about Goedel coding?  "There are infinitely many w such that $w=2^x3^y$ and..."
Comment: @Charles: The paper does mention that the same result holds when adding exponentials provided Schanuel's Conjecture is true. However, even then, how do you define the corresponding logarithms without $\exists$ and $\forall$?
Comment: Hmm.  Is there no total recursive function we can use?  I wasn't able to get one, but the requirements for a Goedel numbering are pretty low.  To put it another way: if I had an odd() predicate I could make a coding 2^a * (2b+1) recursively, so we can't even test the parity of a number if pairing is impossible.  Right?
Comment: Of course you only need one...


Why does deriving the softmax for a single vector come to 0 for me?

Question: There is a lot of material explaining how to calculate the jacobian for the softmax backwards pass, but I find it confusing how to get to the actual errors from the jacobian. The obvious answer would be to sum up the either rows or the columns - it does not matter since the matrix is symmetrical, but analytically it seems the gradient comes out to $0$.
\begin{align}
\frac{\partial h_i}{ \partial z_j} &= h_i  (1 - h_j) &\text{when } i = j  \\[10pt]
\frac{\partial h_i}{ \partial z_j} &= - h_i  h_j &\text{when } i \ne j
\end{align}
Simplifying the case when $i=j$, I get: $h_j(1 - h_j)$
Simplifying the case when $i\ne j$, I get: $- h_j(\sum h - h_j) = - h_j(1 - h_j)$
So adding those two cases up, the gradient with respect to the input should always be $0$. That makes zero sense to me. Where am I going wrong?
Answer: It really is supposed to come out like that. To get the error though, the jacobian is not supposed to be summed directly, but matrix multiplied by the resulting error vector.
Comment: What did you mean when toy say error vector?
Comment: I can't recall exactly as it has been a while. Having to branch on the indices in order to reason out the derivatives definitely does make analysis a lot harder. I did a [little tutorial](https://github.com/mrakgr/The-Spiral-Language#the-softmax-activation) a while back on how to derive the softmax backward pass without those complications using just straightforward algebraic rewriting. Hopefully you will find it helpful.


Which digit is represented by the # symbol?

Question:
So the 2nd column that has the $9$ has to equal to $39$, since there is a 3 being carried. I guess for the 3rd column there is no digits being carried, so the sum has to be less than 10. So i was thinking $0,1,2$ which is $6$ but is there a possibility there could be more than one answer?
Any ideas?
Answer: Hint: Note that
$$
39\#=*3\;+\;**\;+\;**\;+\;**\;\leq93+99+99+99=390\leq 39\#.
$$


How do I apply a patch file?

Question: I downloaded a patch file from mailhandler module and need to apply the changes in order to fix the problem of pop3 accounts not deleting emails after download (import).  How do I install it?
Comment: http://stackoverflow.com/questions/1581644/how-to-apply-a-patch
Comment: Questions asking for links to resources are off-topic as per help center.
Answer: Here are a few links that may help you learn more about patching:

Applying a Patch Manually
Making a Drupal patch with Git (also covers applying)
HowTo: How to apply a patch to a contributed module - Beginner's version (Windows)
Apply Patches on Windows (more methods)
Apply patches on Mac OS
How to apply patches for Drupal modules and files
Comment: Your third link is what I needed.  I had seen all of the other links and didn't find them basic enough.  The one that you found is indeed the one I was looking for.  It's very detailed.  Thanks.
Comment: great, thanks for how to Applying a Patch Manually info !!!
Answer: There's a description in every module under the tab version control. Scroll down to the title "Applying a patch" to find a description about applying patches with git.
Comment: Thanks, I learned something here too.  the "tab version control" used to be called someting else, "Git instructions".  Thanks.  Now, if I only knew what GIT meant!

How do I apply a patch file?


Find the splitting field of $x^6-2x^3-1$ over $\mathbb{Q}$.

Question: Find the splitting field of $x^6-2x^3-1$ over $\mathbb{Q}$.
I know that the real roots of $x^6-2x^3-1$ are $\sqrt[3]{1+\sqrt{2}}$ and $-\sqrt[3]{-1+\sqrt{2}}$. And I know $\zeta_{6}$ is included somehow, but I'm honestly a little lost on how to approach this polynomial. Is there a general way to go about finding splitting fields for a polynomial?
Comment: Splitting field over what base field ?
Comment: Over $\mathbb{Q}$. Sorry for not specifying.
Answer: Let $K$ be the splitting field of $f(x) = x^6-2x^3-1$ over $\mathbb Q$, and $L$ be the splitting field of $y^2-2y-1$ over $\mathbb Q$. We know the following facts:
 - $L = \mathbb Q(\sqrt{2})$;
 - $K$ contains $L$;
 - $f(x)$ factorizes over $L$ as $(x^3-y_0)(x^3 - y_1)$, where $y_0, y_1$ are the two roots of $y^2 - 2y - 1$ in $L$.
Therefore, $K$ is the compositum of the splitting fields $K_i$ of $x^3 - y_i$ over $L$. Since $L \subset \mathbb R$, it does not contain any nontrivial cube root of $1$, therefore $K_i = L(\sqrt[3]{y_i}, j)$ where $j = \exp (2i\pi/3)$. This means that
$$ K = \mathbb Q (x_0 = \sqrt[3]{y_0}, x_1 = \sqrt[3]{y_1}, j),$$
where $f$ factors as
$$ f(x) = (x-x_0)(x-jx_0)(x-j^2 x_0)(x-x_1)(x-jx_1)(x-j^2x_1).$$
This answer is, however, possible only since $f$ is soluble by radicals over $\mathbb Q$. Another, more general answer, would be: factorize $f$ as a product of irreducible polynomials $p_i$; its splitting field is then the compositum of the splitting fields of the $p_i$. Since $f$ is itself irreducible over $\mathbb Q$, we know that $K = \mathbb Q(x)/f(x)$ as a field extension of $\mathbb Q$. But this is a bit of a cheat...


Properties of Determinants: Adding Columns Question

Question: Hello Mathematics community,
I came across two properties of determinants that are causing me great confusion. For the first one, say $x_1$, $x_2$, $x_3$ are column 3-vectors. Then, $
\text{det} [ x_1+x_2\ x_2+x_3\ x_3+x_1] = 2\, \text{det} [ x_1\ x_2\  x_3]$.
For the second one, say $x_1$, $x_2$, $x_3$, $x_4$ are column 4-vectors. Then, $\text{det} [ x_1+x_2\ x_2+x_3\ x_3+x_4\ x_4+x_1] = 0$.
Understanding the technicalities of these two equations is causing me a bit of a headache. I understand the first one makes sense. Since one is essentially adding each column twice, the determinant would be twice as large. However, I cannot understand why the second equation holds true.
Comment: Apply multilinearity of determinant and expand it.
Answer: In your notation,
$$[x_1+x_2\ x_2+x_3\ x_3+x_4\ x_4+x_1 ]
=[x_1\ x_2\ x_3\ x_4]\pmatrix{1&0&0&1\\1&1&0&0\\0&1&1&0\\0&0&1&1}.$$
The matrix $\pmatrix{1&0&0&1\\1&1&0&0\\0&1&1&0\\0&0&1&1}$
has determinant zero.
Answer: By the multilinearity of the determinant, applied to the first column, we have
$$\det[x_1 + x_2,x_2 + x_3,\dots,x_n + x_1] = \det[x_1,x_2 + x_3,\dots,x_n + x_1] + \det[x_2,x_2 + x_3,\dots,x_n + x_1].$$
Now, each of these terms can be simplified a lot by subtracting one column from another. We have
\begin{align}
   \det[x_1,x_2 + x_3,\dots,x_{n-1} + x_n, x_n + x_1] &= \det[x_1,x_2 + x_3,\dots,x_{n-1} + x_n, x_n] \\
 &= \det[x_1,x_2 + x_3,\dots,x_{n-1}, x_n] \\
 &= \dots \\
  &= \det[x_1,x_2,\dots,x_{n-1}, x_n]
\end{align}
by subtracting the first column from the last, the last from the next to last, the next to last from the one before it, and so on. Similarly, we have
\begin{align}
   \det[x_2,x_2 + x_3,\dots,x_{n-1} + x_n, x_n + x_1] &= \det[x_2,x_3,\dots,x_{n-1} + x_n, x_n + x_1] \\
 &= \dots \\
 &= \det[x_2,x_3,\dots,x_n, x_n + x_1]\\
  &= \det[x_2,x_3,\dots,x_{n}, x_1]
\end{align}
by subtracting the first column from the second, then the second from the third, and so on.
As a result, we get
$$\det[x_1 + x_2,x_2 + x_3,\dots,x_n + x_1] = \det[x_1,x_2,\dots,x_{n-1}, x_n] + \det[x_2,x_3,\dots,x_{n}, x_1].$$
Now, the parity of $n$ becomes important. If $n$ is odd, the cyclic shift that takes us from $\det[x_1,x_2,\dots,x_{n-1}, x_n]$ to $\det[x_2,x_3,\dots,x_{n}, x_1]$ requires an even number of column swaps, so these two determinants have the same sign, and add. If $n$ is even, the cyclic shift requires an odd number of column swaps, so these two determinants have opposite signs, and cancel.
Answer: The first one is because\begin{multline}\det[x_1+x_2\ \ x_2+x_3\ \ x_3+x_1]=\det[x_1\ \ x_2\ \ x_3]+\det[x_1\ \ x_2\ \ x_1]+\det[x_1\ \ x_3\ \ x_3]+\\+\det[x_2\ \ x_2\ \ x_3]+\det[x_1\ \ x_3\ \ x_1]+\det[x_2\ \ x_2\ \ x_1]+\det[x_2\ \ x_3\ \ x_3]+\\+\det[x_2\ \ x_3\ \ x_1].\end{multline}Of these determinants, only the first and the last one aren't necessarily $0$. And the last one is equal to $\det[x_1\ \ x_2\ \ x_3]$.
The other determinant is $0$ because the columns are not linearly independent: $$(x_1+x_2)+(x_3+x_4)=(x_2+x_3)+(x_4+x_1).$$


An SCSS cubic bezier function?

Question: Many front end devs know how to use a cubic bezier function. Most of us know of them for their utility in animation easing. It seems that fewer people understand how a cubic-bezier function actually works, and how to create one (probably because that's less useful knowledge). I'm looking for an SCSS port of a cubic-bezier function and can't seem to find one, so I'm trying to make one.
EDIT: I thought I needed a bezier curve, but a polynomial approximation of a sine curve does the trick and is easy enough to pull off in SCSS.
My goal is to alter properties of a group of DOM elements using <code>:nth-child()</code> and a bezier curve to create a sinusoidal difference (or some other curve) from one element to the next. This is my current SCSS code, which will create a linear difference from one element to the next:
<code>$steps: 4;

.class {
    @for $i from 1 through $steps {
        &:nth-child(#{$steps}n + #{$i}) {
            $width: 100 / $steps * $i;
            width: $width+em;
        }
    }
}
</code>
This would compile into CSS something like this:
<code>.class:nth-child(4n+1) { width: 25em; }
.class:nth-child(4n+2) { width: 50em; }
.class:nth-child(4n+3) { width: 75em; }
.class:nth-child(4n+4) { width: 100em; }
</code>
I believe the way to achieve my goal is to multiply the width property in each step by a cubic bezier function that accepts five parameters:
<code>@function cubic-bezier (x1, y1, x2, y2, epsilon) {
    // Epsilon is the width property at a step in the for loop.
}
</code>
Two things need to be solved:

Find or create an SCSS cubic bezier function.
Properly implement that function in the nth-child for loop.
Answer: It seems you need not bezier curve, but some smooth curve with sinusoidal behavior at some interval. If you cannot use Sin function in your code, then try simple polynomial approximation. For example, function 20*x*(x-0.5)*(x-1) looks like one period of sinus at interval 0..1
wolfram alpha plot
Comment: Btw, Compass has a `sin()` function:  http://compass-style.org/reference/compass/helpers/math/#sin
Comment: Yep, it looks like you're right. I don't need a bezier curve because that polynomial sine approximation does the trick. Here's a [codepen](http://cdpn.io/eCiuy). Thank you!

An SCSS cubic bezier function?