How to choose the model hyperparameter after cross-validation when the model fit indices are really similar?

Question: I cross-validated a model using the classification accuracy using leave-one-out-cross-validation (proportion of correctly classified cases). Below is a matrix of accuracies typical to what I see. The rows and columns represent different combinations of two hyper-parameters that are cross-validated. For lower rows and more right columns, the model becomes more flexible, whereas it is far less flexible in the upper left corner of the matrix.
The accuracies are quite similar. Therefore I am hesitant to simply choose the parameter combination that maximizes the fit (lower right). I am too concerned that I may go wrong in choosing one of the extreme categories, as their fit does not differ much from other options.
How should one choose the model hyper-parameters in this case?
<code>      [,1]  [,2]  [,3]  [,4]  [,5]
[1,] 0.699 0.673 0.693 0.686 0.693
[2,] 0.706 0.699 0.686 0.686 0.719
[3,] 0.699 0.699 0.686 0.693 0.719
[4,] 0.686 0.699 0.686 0.693 0.732
[5,] 0.693 0.699 0.680 0.706 0.732
[6,] 0.693 0.673 0.693 0.706 0.732
</code>
Comment: Well, we all do. :) Anyway, see the answer [here](https://stats.stackexchange.com/questions/71184/cross-validation-or-bootstrapping-to-evaluate-classification-performance/71192#71192) I think addresses your question quite closely. In short, probably do a 100x 5-fold CV or bootstrap and you are fine. Also you show accuracy (and OK 3% change is not small) but there are other classification measurements that might help you tease out the best model eg. the parameters at [4,5] might be quite better in terms of Cohen's $k$ than the parameters in [6,5].
Comment: Can you please clarify how big is your sample? In general, repeated CV or repeated bootstrap are more common-place than LOOCV.
Comment: @usεr11852 It is about n=300. I wanted to use as much data for training as possible, but I am not sure actually whether this is ideal.
Comment: @usεr11852 Interesting; I will try the repeated 5-fold CV. However, I am really not sure about the type of fit measure either. There are tons of options. Another one would be AUC for example. It seems they all may suggest a different model is best. In terms of objective I need a model that predicts the underlying class probabilities closely. Classification itself is less crucial. Do you happen to know which fit measure is best for this objective? (This is actually a new question perhaps)
Comment: This means you want a well-calibrated model. Yes, in that case one would use a proper scoring rule like Brier score.
Comment: log likelihood is another possibility to optimize for. in addition, you may want to apply Laplace correction to the probabilities given the small n, depending on the algorithm used.
Answer: That's where Occam's razor comes in: "simpler theories are preferable to more complex ones."
Put into your context: within a similar performance range, the least flexible model is preferable. This makes your model overfit less and thus hopefully more general.
More concretely, this selection is performed using the one standard error rule. Choose the least flexible model within a one standard error range of performance compared to the best model.
The above assumes that you've chosen the performance metric which is adapted to your problem at hand. In addition, leave one out CV has drawbacks on its own but they do not appear to be part of your question.
Comment: Good idea. I remember the one standard error rule from the `glmnet` package (LASSO). It seems useful here too. However I wonder if I can simply apply to it any fit statistic. For example, I could have also used AUC (area under the receiver operating curve) instead of classification accuracy. Would it apply then as well?
Comment: I don't think that the metric would matter in this context, though I do not know that for sure.
Comment: And your concerns about LOOCV? The problem I have is that the sample is not large n=300, so I wanted to use as much data for training as possible.
Comment: You can still use 10 fold CV, which uses 270 out of 300 observations for training each run. Regarding the concerns about LOOCV, check this [post](https://stats.stackexchange.com/questions/27454/how-does-leave-one-out-cross-validation-work-how-to-select-the-final-model-out).
Comment: Hmm in that link you attach they divide by $\sqrt(K-1)$, but shouldn't this be $\sqrt(K)$?
Comment: Dividing by the √(k-1) flavor will yield a bigger std error than dividing by √k, so it is a more conservative choice.


exception in input in python

Question: When running the following code:
try:
   key=int(input())
except ValueError as string:
   print("Error is within:",string)

for example, if one puts 'rrr' this exception will rise, since 'rrr' does not support (int)
However, instead ot putting the actual string, it puts: "invalid literal for int() with base 10: 'rrr' "
How do I make it work so that the variable 'string' actually gets the wrong input that the user gave (in this example, I want it to print: 'Error is within: rrr')
Thanks a lot
Comment: small hint: just post the complete error message
Comment: I can't do so, I have to post a given message that does not include the complete error message.
Comment: Pavel meant, post the exact traceback you are getting with your current code.
Answer: Store the input and convert it to an int separately.
key_str = input()
try:
    key = int(key_str)
except ValueError:
    print("Error is within:", key_str)

Answer: Your issue comes from the fact that the variable string is the error message for a ValueError exception. If you wanted to print out the user's invalid input, you would need to create a variable that stores the user's input before your try/except. For example:
userInput = input()
try:
   key=int(userInput)
except ValueError:
   print("Error is within:",userInput)

Comment: can u redefine `input`?
Comment: @user3678068 Sure. `input` is just a name, so you can rebind it from the built-in function object to the string that function returns.
Answer: You can just parse the error msg :D
print("Error is within:", string.args[0][41:-1])

Comment: `Exception.message` was [deprecated long ago](http://legacy.python.org/dev/peps/pep-0352/#retracted-ideas), and removed from Python 3, which is what the OP is using.

exception in input in python


CURL unexpected T_STRING

Question: I have this page that I'm going a CURL POSTing some info to another site of mine, but I have a error and I can't find the cause.
The error:

Parse error: syntax error, unexpected T_STRING in /home/aaran/public_html/tests/will/1.php on line 13

(that's the line with the CURLOPT_POSTFIELDS on).
Here's the URL to see the script: http://hm.vc/tests/will/1.php
The script:
<?php
foreach($_GET as $key => $value){
    $input[$key] = urldecode(strip_tags($value));
}

$secureurl = "http://hm.vc/tests/will/2.php";

$curl = curl_init();
curl_setopt($curl, CURLOPT_URL, $secureurl);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl, CURLOPT_POST, 1);
curl_setopt($curl, CURLOPT_POSTFIELDS, $input);

$hello = curl_exec($curl);

curl_close($curl);

echo "Hi " . $input['name'] . ", Thanks for blah blah blah blah";
?>

Comment: Your script works for me. -- edit -- nevermind. Can you dump the $input right before $secureurl is set?
Comment: To make the script interpret well to see what $input is holding, just comment the setopt with POSTFIELDS.
Comment: A syntax error means the code could not be tokenised. It has more to do with how you wrote it than how it runs.
Comment: Do any of your get parameters happen to have dashes in their keys?
Comment: Cannot reproduce, works fine for me. Please post an example that actually shows this behavior.
Comment: PHP is notorious for choking on special characters or issues with encoding. Make sure your file isn't hiding a non-printing or control character somewhere.
Comment: This can close as lacking an [mcve].
Answer: Since I don't know what data you're using in the $_GET array, I can only guess, but as mentioned already, do a print_r($input) after creating it to see exactly what data you're passing.
It seems that using an array for CURLOPT_POSTFIELDS requires that all values be scalar. If one of your $_GET variables is an array, you might be running into a problem. See the comments at http://php.net/manual/en/function.curl-setopt.php, specifically 28-Jul-2010, which states:

Be careful when setting the CURLOPT_POSTFIELDS setting using an array. The array used to set the POST fields must only contain scalar values. Multidimentional arrays or objects lacking a __toString implementation will cause Curl to error.
If there is a need to send non-scalar values using a POST request, consider serializing them before transmission.

Could that be it?
Comment: Okay... I have to know how a runtime solution solved a compile-time problem. Can the OP please let us know what happened?

CURL unexpected T_STRING


JavaScript cleaner/purifier?

Question: Is there any way to cleanup JavaScript code?
I want to enable users to post arbitrary JS but i want to filter some of it out, like eval and document.write. Do you know of any tool that can do this?
Comment: I don't get it... why filter `eval` if they can post arbitrary code anyway? Whatever you're trying to prevent by filtering out `eval`, `document.write`, etc., users _will_ be able to accomplish with workarounds. Example: `\u0065\u0076\u0061\u006c("alert (1234)")`
Comment: What do you mean with filter out? Do you want to execute the user's code but stop some functions like the document.write?
Comment: Yes, I want to filter out risky functions like eval or document.write.
Comment: How can you filter/remove code without risking the code stops to work? It would make more sense to check for certain criteria and let the user know the post failed because they had code they are not allowed to.
Comment: @CalinDon Please update your question with what you've mentioned in these comments!
Answer: You can use a linter to filter some bad code out. A good linter is jslint.

JavaScript cleaner/purifier?


iOS : Message = "An error has occurred." in JSON POST

Question: Working in java, not in objective c. Data is not saved in the database despite getting in "Json Data Posted" condition.
I should send the data in the format as shown below to get the json response
<code>{
                "ProjID": "78",
                "Uid": "12",
                "EmailID": "firstname.lastname@example.com",
                "ProjectInviterFQAnswers": [{
                    "slno": "1",
                    "Answer": "a1",
                    "order": "1",
                    "flag": "F"
                }, {
                    "slno": "2",
                    "Answer": "a1",
                    "order": "2",
                    "flag": "F"
                }, {
                    "slno": "1",
                    "Answer": "a1",
                    "order": "2",
                    "flag": "Q"
                }
                ]
            };
</code>
I am sending the dictionary I got in log in the format as shown below.

The differnce between the above code and my log's screenshot is ';' after every key value pair and hence I get the response as mentioned in the title.
Any suggestions to correct the code/logic? Here's what I coded.
<code> NSError *error = Nil;
    NSOperationQueue *queue = [[NSOperationQueue alloc] init];

    NSDictionary *dictionaryArray1 = [NSDictionary dictionaryWithObjectsAndKeys:@"1", @"slno", @"a1", @"Answer", @"1", @"order", @"F", @"Flag", nil];

    NSDictionary *dictionaryArray2 = [NSDictionary dictionaryWithObjectsAndKeys:@"2", @"slno", @"a1", @"Answer", @"1", @"order", @"F", @"Flag", nil];

    NSDictionary *dictionaryArray3 = [NSDictionary dictionaryWithObjectsAndKeys:@"1", @"slno", @"a1", @"Answer", @"2", @"order", @"Q", @"Flag", nil];

    NSArray *arrayAnswer = [NSArray arrayWithObjects:dictionaryArray1, dictionaryArray2, dictionaryArray3, nil];

    NSDictionary *dictionary = [NSDictionary dictionaryWithObjectsAndKeys:@"78", @"ProjID", @"12", @"UID", @"firstname.lastname@example.com", @"EmailID", arrayAnswer, @"ProjectInviterFQAnswer", nil];

    NSLog(@"Dictionary that is being sent to URL is = %@", dictionary);

    NSURL *url = [NSURL URLWithString:@"http://cnapi.iconnectgroup.com/api/QRCodeScan/SaveAnswers"];
    NSMutableURLRequest *request = [[NSMutableURLRequest alloc] initWithURL:url];

    NSData *requestData = [NSJSONSerialization dataWithJSONObject:dictionary options:kNilOptions error:&error];

    [request setHTTPMethod:@"POST"];
    [request setValue:@"application/json" forHTTPHeaderField:@"Accept"];
    [request setValue:@"application/json" forHTTPHeaderField:@"Content-Type"];
    [request setValue:[NSString stringWithFormat:@"%d", [requestData length]] forHTTPHeaderField:@"Content-Length"];
    [request setHTTPBody: requestData];

    NSURLConnection *connection = [[NSURLConnection alloc] initWithRequest:request delegate:self];
    [connection start];
    [NSURLConnection sendAsynchronousRequest:request queue:queue completionHandler:^(NSURLResponse *response, NSData *data, NSError *error){
        if(error || !data)
        {
            NSLog(@"JSON Data not posted!");
            [activity stopAnimating];
            UIAlertView *alertMessage = [[UIAlertView alloc] initWithTitle:@"Error" message:@"Data not saved" delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil];
            [alertMessage show];
        }
        else
        {
            [activity startAnimating];
            NSLog(@"JSON data posted! :)");
            NSError *error = Nil;
            NSJSONSerialization *jsonObject = [NSJSONSerialization JSONObjectWithData:data options:NSJSONReadingAllowFragments error:&error];

            NSLog(@"Response is %@", jsonObject);
            [activity stopAnimating];
        }

    }];
}
</code>
Comment: Hey doesn't your service take XML as input…?
Comment: there could be an issue at the service end...
Comment: my TL yelled at me when I said that there could be an issue at the service end..
Comment: No, it will take as json only. I had this question with previous web service also. Actually it shows xml in web browser, but it will input as json only.
Comment: Is it a WSDL service?
Comment: I am not aware of that but he showed me .net / aspx type webservice. I never worked at webservice end.
Comment: ok.. can u check it from somewhere else such as Poster in firefox?
Comment: let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/40613/discussion-between-deepak-thakur-and-ahmed-z)
Answer: So here's how I solved my own issue.
<code> NSString *str = @"{\"ProjID\": \"78\",\"Uid\": \"12\",\"EmailID\": \"email@example.com\",";
    str = [str stringByAppendingString:@"\"ProjectInviterFQAnswers\": ["];
    str = [str stringByAppendingString:@"{\"slno\": \"1\",\"Answer\": \"a1\",\"order\": \"1\", \"flag\": \"F\"},"];
    str = [str stringByAppendingString:@"{\"slno\": \"2\",\"Answer\": \"a1\",\"order\": \"1\",\"flag\": \"F\"},"];
    str = [str stringByAppendingString:@"{\"slno\": \"1\",\"Answer\": \"a1\",\"order\": \"2\",\"flag\": \"Q\"}"];
    str = [str stringByAppendingString:@"]}"];
    NSLog(@"String is === %@", str);

 NSURL *url = [NSURL URLWithString:@"http://cnapi.iconnectgroup.com/api/QRCodeScan/SaveAnswers/"];
    NSMutableURLRequest *request = [[NSMutableURLRequest alloc] initWithURL:url];

NSData *requestData = [str dataUsingEncoding:NSUTF8StringEncoding];

[request setHTTPMethod:@"POST"];
    [request setValue:@"application/json" forHTTPHeaderField:@"Accept"];
    [request setValue:@"application/json" forHTTPHeaderField:@"Content-Type"];
    [request setValue:[NSString stringWithFormat:@"%d", [requestData length]] forHTTPHeaderField:@"Content-Length"];
    [request setHTTPBody: requestData];
    NSURLConnection *connection = [[NSURLConnection alloc] initWithRequest:request delegate:self];
    [connection start];
    [NSURLConnection sendAsynchronousRequest:request queue:queue completionHandler:^(NSURLResponse *response, NSData *data, NSError *error){
        if(error || !data)
        {
            NSLog(@"JSON Data not posted!");
            [activity stopAnimating];
            UIAlertView *alertMessage = [[UIAlertView alloc] initWithTitle:@"Error" message:@"Data not saved" delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil];
            [alertMessage show];
        }
        else
        {
            [activity startAnimating];
            NSLog(@"JSON data posted! :)");
            NSError *error = Nil;
            NSJSONSerialization *jsonObject = [NSJSONSerialization JSONObjectWithData:data options:NSJSONReadingAllowFragments error:&error];
            NSLog(@"Response is %@", jsonObject);
        }
    }];
</code>
Answer: In my case I got the same error, the issue was that I send the wrong data to the service. Basically, the error was caused by setting the wrong body with the line:
<code>[request setHTTPBody: requestData];
</code>
Between, sendSynchronousRequest is deprecated in iOS9. Use
<code>...
NSURLSessionDataTask * dataTask = [[NSURLSession sharedSession] dataTaskWithRequest:request
                            completionHandler:^(NSData *data,
                                    NSURLResponse *response,
                                    NSError *error) {
if(error || !data)
    {
        NSLog(@"JSON Data not posted!");
        [activity stopAnimating];
        UIAlertView *alertMessage = [[UIAlertView alloc] initWithTitle:@"Error" message:@"Data not saved" delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil];
        [alertMessage show];
    }
    else
    {
        [activity startAnimating];
        NSLog(@"JSON data posted! :)");
        NSError *error = Nil;
        NSJSONSerialization *jsonObject = [NSJSONSerialization JSONObjectWithData:data options:NSJSONReadingAllowFragments error:&error];

        NSLog(@"Response is %@", jsonObject);
        [activity stopAnimating];
    }
}] resume];
</code>


How do I go through 2 list and check if the content of one element in the same as another element in a different list?

Question: private List<Actor> actors = new ArrayList<>();

public void addActors(Movie x)
{
if(actors.isEmpty())
{
    actors.addAll(x.getListOfActors());
}
else
{
    List<Actor> movieActors = x.getListOfActors();
    ArrayList<Actor> tempActors= new ArrayList<Actor>();
    for(int z = 0 ; z <actors.size(); z++)
    {

        for(int n = 0 ; n <movieActors.size();n++)
        {
            if(actors.get(z).getName().equals(movieActors.get(n).getName()))
                actors.get(z).addCount(); // actor count
            else
            {
                tempActors.add(movieActors.get(n));
            }
        }
    }
    actors.addAll(tempActors);
}
}

So each movie object have a list of actors. And each actor objects have a int count object which is initialized at 1. Everything I run addActors(Movie x),
i want to check if there is any actors in movie x that is in List actors. if there is, i want to increment count by 1 else just add it to List actors. This is my current way of doing it, i realized its wrong but i dont know how to fix it. I run the method twice or more, repeated actors will be added to List actors because of actors.addAll(tempActors). Is there a better way to do this ?
update: So the problem isnt with the string comparing. Even if i use .equals, it isnt the result i want.
sample test case:
movie: "frozen"
actors: Kristen Bell, Idina Menzel, Jonathan Groff, Josh Gad
movie: "the boss"
actors: Melissa McCarthy, Kristen Bell, Peter Dinklage, Ella Anderson
so if I use addActors(movie x) on these two movies, each actors should only appear once. In the List actors. And count for kristen bell should be at 2 now. everyone else is 1.(count is number of movies they are in)
however when i run this method with these two movies, my List actors now contains:
Kristen Bell
Idina Menzel
Jonathan Groff
Josh Gad
Melissa McCarthy
Peter Dinklage
Ella Anderson
Melissa McCarthy
Kristen Bell
Peter Dinklage
Ella Anderson
Melissa McCarthy
Kristen Bell
Peter Dinklage
Ella Anderson
Melissa McCarthy
Kristen Bell
Peter Dinklage
Ella Anderson
(sorry for long explanation, I don't know how else to explain this )
Comment: Possible duplicate of [How do I compare strings in Java?](http://stackoverflow.com/questions/513832/how-do-i-compare-strings-in-java)
Comment: No, the problem is not comparing strings. using == or .equals gives me same result.
Comment: @JackieChen by incrementing actor count what do you want to achieve? Do you want to save this count somewhere or what?
Comment: count in each actor is the number of movies they are in , so i add two movies with same actors, the actor count should now be 2. @nullpointer
Comment: you can maintain a `Map` (not literally | more of `Map`) in general to store the count. and inside your `if` increment the count for each actor key.
Comment: okay , but how would i added other actors that are not in the List actors to the list ? @nullpointer
Comment: @JackieChen that is already taken care by your `else` code I guess. You are adding the actors not present already in a list to `tempActors` and eventually to `actors`
Comment: @nullpointer I think my problem is i'm repeatedly adding the same actors in each loop because of that else statement.
Comment: oh if you don't want duplicates , you can use `Set` instead of `List`
Comment: You store the count of occurence in `Actor` for each one ? I don't think an actor should store this information since this depends on the list you are comparing.
Comment: I was think if i can do this in one loop , it should be fine. But set would work so thanks! @nullpointer
Answer: Few open points --
One, I would suggest using foreach for DS like List to iterate through.
Take a look at How does the Java 'for each' loop work?
Two, use equals to compare strings. Help -  How do I compare strings in Java?
Third, use a counter variable, e.g. int counter = 0; which can be used to count the number of duplicate occurrences as
if(actors.get(z).getName().equals(movieActors.get(n).getName())) {
    counter++; //currently just saving the count, you can save the name as well
}

Updating from the comments discussion, to keep a count of actors that appeared in different movies :
You can maintain a Map<Actor,Count> (not literally | more of Map<String, Integer>) in general to store the count. and inside your if increment the count for each actor key.
Further to keep a unique list of actors, would suggest using Set instead of ArrayList. Please read How to use java.Set
Comment: Im not sure how a counter would help? Maybe I didnt explain it well but i edit it just now . The actor count variable is the number of movies they are in so if i added 2 movies with same actor in both movie, the count of that actor would be 2 now because that actor is in the two movies. @nullpointer
Answer: Remove every thing from else condition and replace with following code. Though its not an optimal solution but might serve your purpose.
else {
        List<Actor> movieActors = (List<Actor>) x.getListOfActors();
        for (int z = 0; z < x.getListOfActors().size(); z++) {
            Actor actor = movieActors.get(z);
            if (actors.contains(actor)) {
                actors.get(actors.indexOf(actor)).addCount();
            }else{
                actors.add(actor);
            }
        }
    }

And you have to Override equals method in Actor class
@Override
public boolean equals(Object obj) {
    if(obj instanceof Actor){
        Actor a = (Actor)obj;
        if(this.name.equals(a.name)){
            return true;
        }
    }
    return false;

}

Comment: This assumes that Actor.equals() is implemented by comparing the actor names.
Comment: yea i altered the code. this question doesn't have all the details though. so had to assume a bit.
Comment: This is what im looking for. Thanks ! @AhmedRaaj
Comment: Cheers mate! Happy coding
Comment: `count++` - count may not be visible here. Use `addCount()`
Answer: When you do

actors.get(z).getName() == movieActors.get(n).getName()

I suppose name is a string, in that case it will not be true for same names. You need to do

actors.get(z).getName().equals(movieActors.get(n).getName())

Refer this - How do I compare strings in Java?
Comment: ok, ill fix that. But i think the initial problem will still stand because i'm looking through movieActors, z times which will keep adding duplicate actor objects. @vijay jain
Comment: Correct me, if I am wrong, It will add duplicates if there are already duplicates in actors or movieActors. In that case you can opt for a set/hashset and override equals and hashcode methods in Actors class.
Comment: you're correct , it keeps adding duplicates because its loop n*z times. Using hashset would work. If i can do this using one loop , it should be fine , but not sure how.
Answer: Use the ".equals" instead of "=="
Answer: Same as @Ahmed Raaj.
else{

        List<Actor> movieActors = x.getListOfActors();
        List<Actor> duplicateActors = new ArrayList<>();
        List<Actor> uniqueActors = new ArrayList<>();

        for(Actor eachActor : movieActor){
            if(actors.contains(eachActor))
                duplicateActors.add(eachActor);
            else
                uniqueActors.add(eachActor);
        }

        for(Actor eachDuplicateActor : duplicateActors){
            for(Actor eachOriginalActors : actors){
                if(eachOriginalActors.getName().equals(eachDuplicateActor.getName())
                        eachOriginalActors.addCount();
            }
        }

        actors.addAll(uniqueActors);
    }

I haven't tested the code, so there might be errors
Answer: I think you should reverse the order of the loops, and only add the actor if it is not found:
for(int n = 0 ; n <movieActors.size();n++)
{
    boolean found = false;
    for(int z = 0 ; z <actors.size(); z++)
    {
        if(actors.get(z).getName().equals(movieActors.get(n).getName())) {
            actors.get(z).addCount(); // actor count
            found = true;
            break;
        }
    }
    if (!found) {
        tempActors.add(movieActors.get(n));
    }
}

But I don't get the signification of count
Comment: thanks for the input , i found that if i just change tempActors to a hashset , everything will work fine.


Advanced Migration - update nodes

Question: I'm a little bit new in Drupal but experienced in PHP.
I would like to migrate data from CSV and assign to existing nodes in DB.
My question is about the possibility to match processing rows with existing data from the database.
I mean, I have CSV file with data and with foreign key called: SERVICE_ACTION and now I would like to assign that data to existing NODE which hasn't SERVICE_ACTION key but has different KEY which is assigned to another specific entity with Service Action key. How can I get ID of that entity in migration script to assign?
Perhaps, I need target_id to assign newly created paragraph to the specific node. I'm not sure what I'm working bad.
langcode: en
status: true
dependencies:
  enforced:
    module:
      - xxx_migration
      - paragraphs
id: xxx_release_notes
migration_tags:
  - custom-migrate
  - soap-apis
migration_group: xxx_soap_api
label: 'xxx release notes'
source:
  plugin: csv
  data_fetcher_plugin: file
  path: modules/custom/xxx_migration/artifacts/releases_notes.csv
  header_row_count: 1
  keys:
    - id
  column_names:
    -
      id: 'Unique Id'
    -
      title: Title
    -
      body: 'Post body'
    -
      service_action_code: 'Service Action Code'
process:
  type:
    plugin: default_value
    default_value: people
  field_service_action_code:
    plugin: migration_lookup
    migration: xxx_release_notes
    source: service_action_code
destination:
  plugin: 'entity_reference_revisions:paragraph'
  default_bundle: release_note
migration_dependencies:
  required: {  }
optional: {  }

here is my CSV file:
id,title,body,service_action_code
1,TITLE,example body,PassengerDetailsRQ
2,TITLE2,example body2,ePaymentRQ

Comment: I don't know if it's possible to query the database from that. Maybe with something like a callback if that's possible? I'd to that myself taking https://github.com/GiantRobot/csvimport as a starting point.
Comment: AFAIK the migrate module can not update entities it has not created itself. You'll have to create your own module/code, I don't think the Migrate module fits your use case.
Comment: So you're wanting to look up a node entity id reference for `field_service_action_code` using the value `service_action_code` via a field value on the referenced node?
Answer: I don't know the exact answer. But maybe this information can get you on the right track.
First the migration process has the ability to update earlier migrated entities, it does this with the help of high-water-marks and timestamps (see Drupal's documentation). Maybe you can do a trick to use this feature. Furthermore there is a lot of good documentation about the migration-process, I recommend this site, an extensive tutorial about the process in 31(!) steps/days, https://understanddrupal.com/31-days-of-migrations or https://www.phase2technology.com/blog/migration-making-it-all-work. Behind it some of the "Drupalstars" from the migration and comprehensibly written. Hope you find your answer there.

Advanced Migration - update nodes


Postfix - forwarding some email addresses to an alias through external SMTP service

Question: I'm trying to set up a Postfix server on Google Cloud, which blocks outgoing SMTP ports. My problem is that one email address (say email@example.com) needs to be an alias for an external email address (firstname.lastname@example.com); all emails sent to email@example.com need to be forwarded to email@example.com. I also have other email addresses that simply need to be delivered locally.
I am able to get Postfix to attempt to send all emails to firstname.lastname@example.com to email@example.com using virtual alias mappings, but because SMTP ports are blocked, the connection doesn't go through to example2.com's SMTP server. I want to get Postfix to send these emails through Mailjet on port 2525 so that the connection isn't blocked. Unfortunately, even when relayhost is set to in-v3.mailjet.com:2525, Postfix doesn't attempt to relay the emails and instead tries to send them directly.
I'm on Ubuntu 16.04.
Comment: It's `relayhost`, not `relay_host`.
Answer: When you do any relay directive, postfix by default will try to lookup the mx for that domain, so you have to tell postfix to use the a-record provided using brackets, see my relayhost directive below.
relayhost = [vps1.domain.com]:26

I'm using an off port to get around my ISP blocking smtp, so this forces postfix to go straight to that a-record and connect to send email.


using pip3: module "importlib._bootstrap" has no attribute "SourceFileLoader"

Question: I have installed pip for python 3.6 on Ubuntu 14. After I run
sudo apt-get install python3-pip

to install pip3, it works very well. However, after installation, when I am trying to run
pip3 install packagename

to install a new package, something strange occurs:
File "/usr/lib/python3/dist-packages/pkg_resources.py", line 1479, in <module>
 register_loader-type(importlib_bootstrap.SourceFileLoader, DefaultProvider)
AttributeError: module "importlib._bootstrap" has no attribute "SourceFileLoader"

It seems that I did nothing wrong, and I really cannot figure out the reason.
Comment: @phd Why did you post that. The reason people came here is because the first command of the top answer does not work.
Comment: Does that happen for every package you try to install?
Comment: See https://stackoverflow.com/a/44354166/7976758
Comment: It looks like issue is with python version.
Comment: @SamChats yep… Actually every time I type "pip3" this problem occurs, such as "pip3 --version" etc.
Comment: Correct answer at this stage is: https://stackoverflow.com/questions/41720578/modulenotfounderror-in-tracebacks-with-python3-6-on-linux
Comment: > pip uninstall setuptools
> pip install setuptools
worked for me
Answer: If you're getting this error running pip install dotenv, this is because the package is called python-dotenv not dotenv.
This worked for me:
sudo pip install python-dotenv

Comment: I think this answer is specific to dotenv
Comment: It is so bad that the package name used in import statement is different than the one used in installation
Comment: `sudo pip3 install python-dotenv` if you have pip3 installed alongside pip for python2
Comment: Saved my life! `poetry add python-dotenv` :)
Comment: Agreed with @alramdein, especially because the dotenv package exists :)
https://pypi.org/project/dotenv/
Answer: Faced the same problem. I think this is because python3.6 and pip3 were installed from different sources.
I suggest using python's inbuilt facility to install pip i.e
python3 -m ensurepip --upgrade

This should install pip3 and pip3.x where x in python3.x.
Same works for python2 also.
Comment: '/usr/bin/python3.6: No module named ensurepip' Any ideas?
Comment: Is `ensurepip` available on Ubuntu? On my Ubuntu environment, I can't import it. Maybe, on many other environments, `ensurepip` is not available.
Comment: @H.Jang
Yeah. Its a bug in Ubuntu.
https://bugs.launchpad.net/ubuntu/+source/python3.4/+bug/1290847
Comment: Hey @Ibrahim.H, haven't checked it myself so can't say
Comment: That's strange! According to https://docs.python.org/3/library/ensurepip.html `ensurepip` is part of python standard library.
Are you sure you installed python correctly and is accessible as well?
Comment: @azhar22k is `ensurepip` available for python3.7 installed from `deadsnakes/ppa`repository?
Comment: not working. I already reinstalled pip3 and pipenv
Answer: Tried to install Tensorflow in venv on Windows 10 machine with python 3.8 and got the same issue.
What helped for me  was:
pip install setuptools --upgrade

Comment: Also helps for Ubuntu 18.04
Comment: helped also on Pop!_OS 21.10 as well
Comment: I have `Pop!_OS 20.10` based on Ubuntu and this helped
Comment: this helped me during the installation of Localstack via pip
Answer: I had the same problem on my ubuntu 18.04 with python 3.6. None of the above methods helped, but this one solved the problem:
pip3 uninstall setuptools

Comment: I had issues with fs-uae-launcher not starting on Debian Buster because:
AttributeError: module 'importlib._bootstrap' has no attribute 'SourceFileLoader'
Uninstalling setuptools fixed it.
Comment: Thanks for the solution, none of the above solution worked and this issue was annoying my day :)
Comment: `pip3 uninstall setuptools` make it worse
`pip3 install setuptools`same error as in topick
Answer: I had the same error whatever I asked to pip. I gave a look to this page: https://packaging.python.org/tutorials/installing-packages/
That line is the one that solved my problem:
python3 -m pip install --upgrade pip setuptools wheel

Comment: After upgrading from Ubuntu 19.10 to 20.04 I had this problem with pip3. Nothing I'd found worked. This finally solved it.
Comment: On MacOS Monterey 12.6 and using python 3.9.9. This command fixed the issue while trying to install socketio 0.2.1
Answer: When updating from python3.4 to python3.6 on ubuntu 14.04. The following solved me:
wget https://bootstrap.pypa.io/ez_setup.py -O - | python3

Comment: This one worked for me, just added sudo to python3
wget https://bootstrap.pypa.io/ez_setup.py -O - | sudo python3
Answer: pip install setuptools --upgrade

This command solved my issue. It fixed my problem.
Answer: That's because you are using an old version of setuptools, check up this issue.
Answer: If you face this issue in anaconda environment, simply upgrade setuptools using the following:
conda install -c conda-forge setuptools

Answer: I had faced the same issue on Ubuntu 19.10 and now I upgraded to Ubuntu 20.04 and faced the issue again. This issue is due to broken pip3. So whenever you enter pip3 and hit enter it will show the same error. So instead of using "pip3 uninstall setuptools" use the below code
python3 -m pip uninstall setuptools

It resolved my issue 3rd time
Answer: I met the same problem, this is the key:
curl -sS https://bootstrap.pypa.io/get-pip.py | sudo python3

Answer: I am facing the same problem, which is solved by downloading the source files of the setuptools and installing the module manually.
The setuptools can be downloaded here:
https://pypi.org/project/setuptools/

After downloading, unzip the package first, then cd to the directory and run
python setup.py install --user

Answer: For me the error happened while trying to create a virtual env with python 3.8:
sudo virtualenv venv -ppython3.8

And after trying all the answers here, finally the problem solved by installing the new version of virtualenv (20.0.7):
sudo pip3 install virtualenv

Answer: I encountered this error message triggered by a slightly different situation which I'll mention here for anyone who finds this.
This same error also occurs when installing the distribute Python package (which is currently just a compatibility layer in front of setuptools) in Python 3.6 or newer.
In my specific situation I discovered this as I was using pyzmail which has been somewhat abandoned and depends on distribute.
Collecting distribute
  Downloading distribute-0.7.3.zip (145 kB)
    ERROR: Command errored out with exit status 1:
     command: /var/lang/bin/python -c 'import sys, setuptools, tokenize; sys.argv[0] = '"'"'/tmp/pip-install-ssqyqflj/distribute/setup.py'"'"'; __file__='"'"'/tmp/pip-install-ssqyqflj/distribute/setup.py'"'"';f=getattr(tokenize, '"'"'open'"'"', open)(__file__);code=f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))' egg_info --egg-base /tmp/pip-pip-egg-info-hgbjn0js
         cwd: /tmp/pip-install-ssqyqflj/distribute/
    Complete output (15 lines):
    Traceback (most recent call last):
      File "<string>", line 1, in <module>
      File "/tmp/pip-install-ssqyqflj/distribute/setuptools/__init__.py", line 2, in <module>
        from setuptools.extension import Extension, Library
      File "/tmp/pip-install-ssqyqflj/distribute/setuptools/extension.py", line 5, in <module>
        from setuptools.dist import _get_unpatched
      File "/tmp/pip-install-ssqyqflj/distribute/setuptools/dist.py", line 7, in <module>
        from setuptools.command.install import install
      File "/tmp/pip-install-ssqyqflj/distribute/setuptools/command/__init__.py", line 8, in <module>
        from setuptools.command import install_scripts
      File "/tmp/pip-install-ssqyqflj/distribute/setuptools/command/install_scripts.py", line 3, in <module>
        from pkg_resources import Distribution, PathMetadata, ensure_directory
      File "/tmp/pip-install-ssqyqflj/distribute/pkg_resources.py", line 1518, in <module>
        register_loader_type(importlib_bootstrap.SourceFileLoader, DefaultProvider)
    AttributeError: module 'importlib._bootstrap' has no attribute 'SourceFileLoader'

Answer: I had the same issue when I tried to install the Slate package in Windows 10, Python 3.7.4 version:

AttributeError: module 'importlib._bootstrap' has no attribute 'SourceFileLoader'

The instruction that generated the error:
C:\WINDOWS\system32>python -m pip install slate

The instruction that worked:
C:\WINDOWS\system32>python -m pip install https://github.com/timClicks/slate/archive/master.zip

Answer: Traceback (most recent call last):
File "/usr/bin/pipenv", line 6, in <module>
from pkg_resources import load_entry_point
File "/home/myuser/.local/lib/python3.7/site-packages/pkg_resources.py", line
1479, in <module>

Mine looked pretty similar, but for some reason I had a python installation in my home directory .local folder.
I did some of the other answers in this thread to ensure I had good local copy of python, then did:
rm -rf ~/.local

Answer: I had the same problem with my cloud computer. If all above didn't work for you don't worry. Here's how I resolved it:

Download the pip file (pip-version.tar.gz) from:

https://pypi.org/project/pip/#files

For cloud, use this
curl https://files.pythonhosted.org/packages/8e/76/66066b7bc71817238924c7e4b448abdb17eb0c92d645769c223f9ace478f/pip-20.0.2.tar.gz --output pip.tar.gz

Extract the content of the file and cd into the directory.
Run the following in the directory

python3 setup.py install --user

You should have pip3 working without errors.
Comment: Still get same error - Ubuntu 14: AttributeError: module 'importlib._bootstrap' has no attribute 'SourceFileLoader'
Answer: Just go inside the /usr/lib/python3/dist-packages/, first copy  setuptools file somewhere and then delete the setuptools. Everything will be okay for deleting you can use:
sudo rm -r setuptools

for copying
sudo cp -r setuptools /...Desktop/

After that if it gives errors just:
sudo pip3 install setuptools==3.8.1

to download again.
Answer: pip3 install setuptools --upgrade

This also cured the issue on Python 3.9 running on Windows 10 and even on a custom Docker image.
Answer: I was having the same issue while using docker-compose. This exact error can be caused by not being the root user. Running the same commands with sudo fixed it for me. I don't not have setup-tools installed, and I'm running pip3. My issue was that IntelliJ didn't have sudo rights, so i had to do it from the terminal.
Answer: Above solutions were not working in my case for Ubuntu 20
If you run the following command:
sudo apt install python3-setuptools

Then you might get the result:
Reading package lists... Done
Building dependency tree
Reading state information... Done
python3-setuptools is already the newest version (45.2.0-1).
0 upgraded, 0 newly installed, 0 to remove and 0 not upgraded.

But to actually solve it and re-install setuptools try following commands:
sudo apt download python3-setuptools
sudo dpkg -i python3-setuptools_45.2.0-1_all.deb

Note: Change the version of the python package that is downloaded


Manually changing URL alias values via phpmyadmin? What does this affect?

Question: I have a bunch of aliases in my url_alias table. I want to change the source of certain rows, but I'm not sure if it would affect anything. What I need to know is if the column PID in the url_alias table is linked to anything else. Currently I just want to switch node/33 to node/2343, but im afraid I might break something if im doing it via phpmyadmin. I can't do it via the site as I have over 100+ entries I have to modify. The easiest way is by doing it in mysql.
Also is there a drupal database table map I can generate that shows me how each table is linked to each other?
Answer: Doing any manual updates to the Drupal database is a bad idea unless you know exactly what you are doing.
The {url_alias} table is written to with path_save().  If you look at the source, two hooks may be fired, depending on whether the path is new or update: hook_path_insert() or hook_path_update().
So, if you update  {url_alias} manually, you don't give any other modules the chance to react via the hooks.  Whether or not anything bad will happen depends on whether your system has any of these hooks in use.  Off the top of my head, I am unaware of any modules that do, but you would need to run a module_implements('path_insert') and module_implements('path_update') to be sure.
Your safest bet is to always use the API.  Write a standalone script, and execute it with drush -u 1 scr yourscrpt.php to make sure all of your hooks execute.


Are there any suggestions to improve my code (without decorators)?

Question: The code is about a user trying to guess a number between 1 and 10
from random import randint

answer = None
random_number = randint(1, 10)

The following block forces the user to enter an integer number and return its value
def ask_int_number():
    try:
        num_guess = int(input("Pick a number from 1 to 10: "))
    except ValueError as err:
        num_guess = None
        print("You must enter an integer!")
        print(err)

    return num_guess

Checks if the number satisfies the game's conditions
1- number between 1 and 10
2- too low if smaller, too high if greater, correct if equal
def check_number(guess):
    if num_guess in range(1, 11):
        if num_guess < random_number:
            print("Too low!")
            return False
        elif num_guess > random_number:
            print("Too high!")
            return False
        else:
            print("Correct!")
            return True
    elif type(num_guess) is int:
        print("Number must be between 1 and 10")

    return False

Checks if the user wishes to continue playing
def check_answer():
    answer = input("Play again? Y/N\n")
    answer = answer[0].lower()
    if answer not in ("y", "n"):
        print("Please answer by 'Y' or 'N'")
        return False

    return answer

Function to run the game
def run_game():
    while answer != "n":
        num_guess = ask_int_number()
        if not check_number(num_guess):
            continue
        answer = check_answer()
            if answer == "y":
            random_number = randint(1, 10)

run_game()

Comment: if your code is working and you want to improve its readability/performance -- then there is a special place for this called https://codereview.stackexchange.com, but in either way you need to provide description of what your code does
Comment: Hello, I am new to programming. I am taking my second course on python. This is a simple number guessing game (from 1 to 10), and all is working well. However, I want to see if there are any tips or remarks regarding the structure of the program and the control flow. Thank you.
Comment: I hope the format is better now. I am new to programming and being active in the community.However, I shall learn about the standards with time. Thank you all for your messages and help.
Answer: There are much cleaner ways to do it but here is a quick one:
import random

num = []

def ran_gen():
    global num
    for x in range(1):
        num = random.randrange(0, 10)
    number_guess()

def number_guess():
    print('''

    Guess a number between 1-10

    ''')
    while True:
        try:
            guess = int(input(':>  '))
            if guess == num:
                print('You guessed correct!')
                exit()
            if guess != num:
                print('That\'s not the number, guess again')
        except ValueError:
            print('That is not a number')

ran_gen()

Comment: Thank you very much. Your contribution was very insightful and helpful. It will definitely help me to improve my approach and how I structure my program. It is obvious that there is lots of code and conditions which I did not need to use. Thank you.


Decision trees and backward pruning

Question: By building the complete tree and pruning it afterward we are adopting a strategy of postpruning (or backward pruning) rather than prepruning (or forward pruning).
Prepruning would involve trying to decide during the tree-building process when to stop developing subtrees. It's attractive because allows to avoid all the work of developing subtrees only to throw them away afterward.
What are the benefits of post-prunning then?
Answer: Oh well, gotta answer my own question. Quotting "Data Mining: Practical Machine Learning Tools and Techniques",

..postpruning does seem to offer some advantages. For example, situations occur in which two attributes individually seem to have nothing to contribute but are powerful predictors when
  combined—a sort of combination-lock effect in which the correct combination of the two attribute values is very informative whereas the attributes taken individually are not. Most decision tree builders postprune; it is an open question whether prepruning strategies can be developed that perform as well.

So basically while building a whole decision tree (rather that a subset of it as in pre-prunning) we may often come up with powerful "combined predictors" which are plausible to notice only when the whole tree (rather than its subset) is built.
Moreover, this is the recommeded approach and forward pruning is rarely used at all.

Decision trees and backward pruning


Consulta no MySQL não ordena corretamente

Question: Tenho uma tabela de jogos chamada game, uma tabela de plataformas de jogos chamada plataformas e uma tabela que faz o relacionamento N-para-N entre as duas chamada game_plataforma.
Tenho uma consulta que tem que buscar uma plataforma de jogos, mas tem que ordenar de acordo com o último jogo que foi cadastrado nela.
Tenho a seguinte consulta:
select DISTINCT(p.id), p.slug, p.nome,gp.id_plataforma
                                from game g
                                join game_plataforma gp on g.id=gp.id_game
                                join plataformas p on gp.id_plataforma=p.id
                                where g.ativo='1'
                                group by p.nome
                                order by g.dia DESC
                                limit 4

Só que não está ordenando corretamente. Ele esta ordenando alfabeticamente pelo nome da plataforma.
Fiz o seguinte teste:
select id_plataforma from game_plataforma order by id DESC;

E ele retornou certo esses valores abaixo para o campo id_plataforma:

2, 22, 2, 25, 2, 2, 2, 2, 2, 25, 2, 1, 2, 2, 23, 6, 6, 22, 2, 22

Agora, quando executo esse aqui:
select distinct(id_plataforma) from game_plataforma order by id DESC;

Ele volta isso aqui para os mesmos campos:

25, 1, 23, 6, 2, 22

E com group by dá nisso:
select id_plataforma from game_plataforma group by id_plataforma order by id DESC;

25, 1, 23, 6, 2, 22

Eu estou ficando louco ou tem alguma coisa errada?
Estrutura da tabela game_plataforma:

o que preciso que venha são os ids de plataforma nesta ordem:

2, 22, 25, 1, 23
Comment: Sua pergunta está um tanto confusa. Além de um monte de números de ids, o que há na tabela `game_plataforma`? Ela é uma tabela de junção de um relacionamente N-para-N entre as tabelas `plataformas` e `game`? Você diz que tem que buscar a categoria, mas não tem nenhum campo na sua query chamado "categoria" ou que sugira ser uma categoria. Ou por acaso, por categoria você quis dizer plataforma? Enfim, diga ao menos quais são os campos de cada tabela e se possível mostre alguns dos dados que nelas estão.
Comment: a categoria he a plataforma e sim o game_plataforma he uma tabela relacional de n para n vou mandar um ss do que tem nela.
Answer: Comecemos por essa consulta aqui:
select id_plataforma from game_plataforma order by id DESC;

Observe que você está selecionando um campo enquanto está ordenando por um outro campo. Não deve ser isso o que você queria. O campo id que ele usa para ordenar é apenas a ordem de inserção dos registros nessa tabela. Isso vai trazer apenas uma lista de ids de plataformas que estão relacionadas a algum jogo qualquer o número de vezes em que estejam relacionados e ordenados de acordo com a ordem em que foram inseridos. Isso não vai trazer nada de útil para você.
Já essa consulta aqui:
select distinct(id_plataforma) from game_plataforma order by id DESC;

Isso trás algo parecido com a consulta anterior, mas sem repetições. Uma lista de ids de plataformas que estejam relacionadas a algum jogo qualquer ao menos uma vez, ordenadas de acordo com a ordem em que foram inseridas. Também não é algo lá muito útil.
select id_plataforma from game_plataforma group by id_plataforma order by id DESC;

Esse group by vai ser apenas uma forma bizarra de se fazer o distinct da consulta anterior.
Bem, vamos deixar esses testes de lado e olhar a sua consulta original:
select DISTINCT(p.id), p.slug, p.nome,gp.id_plataforma
                            from game g
                            join game_plataforma gp on g.id=gp.id_game
                            join plataformas p on gp.id_plataforma=p.id
                            where g.ativo='1'
                            group by p.nome
                            order by g.dia DESC
                            limit 4

Você está listando dados de plataformas, mas acaba indo até a tabela de jogos para buscá-los. Se não fosse pelo group by e pelo distinct, o número de resultados seria provavelmente o número de registros na tabela game_plataforma, o que significa várias vezes as mesmas plataformas multiplicadas pelos número de jogos ativos em cada plataforma.
Além disso, parece que você não entende como funciona o DISTINCT. O DISTINCT se aplica a todo o conjunto de colunas selecionadas, e não apenas a essa que está entre parênteses. Aliás, esses parênteses não estão fazendo absolutamente nada.
Acho que o que você queria no fim das contas é isso:
SELECT p.id, p.slug, p.nome
FROM game g
INNER JOIN game_plataforma gp ON g.id = gp.id_game
INNER JOIN plataformas p ON gp.id_plataforma = p.id
WHERE g.ativo = '1'
GROUP BY p.id
ORDER BY MAX(gp.id) DESC

O truque aqui é que você quer só informações de plataformas, mas tal como na sua consulta original, precisa ir navegando até a tabela de jogos para lá pegar o campo ativo (o que também já elimina as plataformas para as quais não há jogos). Isso daí iria repetir as informações de plataformas, não fosse pelo nosso GROUP BY.
Para o GROUP BY funcionar, é importante que nenhum campo das tabelas gp ou g apareça no SELECT ou no ORDER BY sem usar-se alguma função agregadora. Caso contrário, eles iriam bagunçar com o GROUP BY que joga todas elas em um só registro. O propósito das funções agregadoras é exatamente a de juntar vários registros em um só para poderem ser usados quando há um GROUP BY.
Entretanto, para fazer a ordenação no ORDER BY eu preciso de uma informação da tabela gp (qual é a mais recente), e portanto, eu preciso de alguma função agregadora. A função agregadora usada no ORDER BY é a função MAX que escolhe o maior valor dentre todos aqueles que serão agregados, no caso o maior id da tabela gp. Como os ids estão ordenados por ordem de inserção, então o maior id é o mais recente.
Comment: Incrível é isso mesmo . pode me explicar melhor como chegou nisso pois o que quero fazer é criar abas que se ordenem  de acordo com as ultimas postagens de games nas plataformas
Comment: haha cara deu certo muito obrigado mesmo olha ai como ficou http://desapegogames.com.br/ ( logo abaixo do banner de bem vindo nas abas )
Comment: @JasarOrion Atualizei a resposta com a explicação. ;)
Comment: @JasarOrion Ah, e por sinal, achei interessante o seu site. ;)
Comment: entendi um pouco me deu uma clareada boa . muito obrigado agradeço a ajuda.


How can I get the sub-navigation to show up in the sidebar on child pages

Question: Drupal newb here :) So I may not have the Drupal lingo correct in my explanation...
I have a menu block called "Sub Navigation".  Here are my configurations:

(I've inherited this site so I'm not sure if this is a default block or not etc)
So, the navigation shows up just fine in the sidebar of parent pages, but it does not on any child page. (The admissions parent page has a context configuration, is why it is omitted here).
Am I missing a configuration here?
Thanks for any help!
Comment: is the url of your child page  `/admissions`?
Comment: Some of them are, but it is also not showing up under any other child page...  for example, it shows on the About page -`/about`, but not on any About child page - `/about/presidents-office`, `/about/policies` etc
Comment: If the subpages use panels, blocks could be disabled. Just an idea before delving into the issue further.
Comment: I don't see the panels module installed...
Answer: I got some help with this, and what it needed was for this checkbox to be selected:


Interpreting the effects of dummy interactions

Question: Warning
This question is quite long, and maybe a lot of you will think it is too long. I however thought, and hope, that if this question gets a proper answer, it will actually be a really good post to help people with getting a quite comprehensive understanding of the slightly more advanced workings of dummy variables. Related to this, please feel free to edit this question if you think some parts could be made clearer.
Background
Although I think I am getting quite up to standards when interpreting dummy interaction effects, I always get confused in some situations. For example when trying to control for a sample imbalance. Added because of a question in the comments: The problem with the sample imbalance that I perceive, is that because I have substantially more females in my sample. I am worried that the effects that I pick up (not only for the treatment, I just wanted to not over-complicate the example), are not purely attributable to the variables I include, but also to potential confounding characteristics which are more present in the female subsample.
In this example, there are three types of variables:

Choice, a dummy variable, which is the dependent variable in all regressions.
treatment, a dummy variable (treatment = 1, control = 0)
Gender, a dummy variable (Male or Female)

.
one <- glm(Choice ~ as.factor(gender), family = binomial(link=logit), data=data)
two <- glm(Choice ~ as.factor(treatment), family = binomial(link=logit), data=data)
three <- glm(Choice ~ treatment + as.factor(gender), family = binomial(link=logit), data=data)
four <- glm(Choice ~ as.factor(gender):as.factor(treatment), family = binomial(link=logit), data=data)
five <- glm(Choice ~ as.factor(gender):as.factor(treatment) +  as.factor(gender), family = binomial(link=logit), data=data)
six <- glm(Choice ~ as.factor(gender)*as.factor(treatment), family = binomial(link=logit), data=data)
====================================================================================================
                                                             Dependent variable:
                                         -----------------------------------------------------------
                                                                   Choice
                                            (1)       (2)       (3)       (4)       (5)       (6)
----------------------------------------------------------------------------------------------------
treatment                                                     0.200*
                                                              (0.120)

Male                                     -0.340***           -0.340***            -0.140    -0.140
                                          (0.120)             (0.120)             (0.170)   (0.170)

as.factor(treatment)1                               0.200*                                  0.350**
                                                    (0.120)                                 (0.140)

Female:as.factor(treatment)0                                            0.210
                                                                        (0.170)

Male:as.factor(treatment)0                                               0.077
                                                                        (0.200)

Female:as.factor(treatment)1                                            0.570***   0.350**
                                                                        (0.180)   (0.140)

Male:as.factor(treatment)1                                                        -0.077    -0.430*
                                                                                (0.200)   (0.240)

Constant                                 -0.210*** -0.420*** -0.300*** -0.590*** -0.380*** -0.380***
                                          (0.071)   (0.080)   (0.090)   (0.140)   (0.099)   (0.099)

----------------------------------------------------------------------------------------------------
Observations                               1,242     1,242     1,242     1,242     1,242     1,242
Log Likelihood                           -840.000  -843.000  -839.000  -837.000  -837.000  -837.000
Akaike Inf. Crit.                        1,685.000 1,690.000 1,684.000 1,683.000 1,683.000 1,683.000
====================================================================================================
Note:                                                                    *p<0.1; **p<0.05; ***p<0.01

My understanding
Regression 3: I know that normally, adding a dummy, causes an intercept change, between the base group (treatment=0). However, my experiment had a gender imbalance, so I wanted to correct for that, adding a gender dummy. Now I started to doubt the interpretation. To check, I ran the regression once with only with the gender and once with only the treatment, once with both. Since the coefficients do not change, I have to assume that BOTH dummies signify independent intercept changes. So actually I am in no way controlling for the gender imbalance.
Regression 4: Here I only interacted the gender with the treatment. As there is no coefficient on as.factor(gender)2:as.factor(treatment)1, I assume that this is the base level, which I believe means that all other coefficients are the interaction effects, compared to the base level. Thinking about this, I realised this is super uninformative, because if I understand correctly, it says nothing anymore about the effects on Choice, just how one compares to the other.
Regression 5: Compared to regression (4), I now added a separate gender dummy. It now seems that I have what I want, because I get a treatment effect for men and a treatment effect for women. The gender dummy, if I understand correctly, now simply gives me the difference between men and women for the non treatment group.
Regression 6: I thought I would get the most information by interacting the dummmies, and also add them separately, but I think this does not work, because there are only 6 different groups. The treatment effect for men in this regression is I believe, the treatment effect plus the treatment interaction, which coincides with the effect of as.factor(gender)2:as.factor(treatment)0 in regression 4.
My questions

Are my interpretations above correct?

Am I correct in saying that only regression (5), gives me the treatment effect, corrected for the sample imbalance? If so, why did it necessitate me to add a separate gender dummy?

Which variable/interaction, tells me whether the difference in treatment effect between men and women is significantly different? Do I need to run even another regression for this?
Comment: Why are you speaking of imbalance? Adding gender is adding a second factor to control for and test for, it seems nothing to do with imbalance by gender.
Comment: It looks like you are using dummy variables as categorical factors, aren't you? Dummies are quantitative variables in which you encode, recode your initial categorical variables, and they should enter the model as (sets of) quantitative predictors. covariates.
Comment: @ttnphns Thank you for your comment. The problem is that because I have substantially more females in my sample. As a result, I am worried that the effects that I pick up (not only for the treatment, I just wanted to not over-complicate the example), are not purely attributable, to the variables I include, but also confounding characteristics which are more present in the female subsample.
Comment: @ttnphns I think I understand what you are getting at, but not completely. Is it possible to provide me with a basic example, and a little explanation of how that actually changes the approach?
Comment: Your total examle isn't very good, didactically. Because both your factors, treatment and gender, are dichotomous, two-level, and coded as binary. In such a case, it makes no difference whether to enter them as categorical factors or quantitative regressors (in the form of dummies). Still, your question title reveals that you are interested in the behaviour of dummies. I might recommend to post a question with two factors, both 3-level or one is 2-level and the other is 3-level. If your goal is to get understanding of how dummies behave.
Comment: @ttnphns Thanks, I will consider this. The problem is that this question is part of my paper. So although I can create a different example, this example is the question that I would really need an answer to.
Answer: I will try to answer your question, feel free to comment if somthing is unclear or i have misunderstood you.
1) to your question: Are my interpretations above correct?
I will try to go trough the models one at a time, rather than answer wit a simple yes or no.
Lets look at model 1.
one <- glm(Choice ~ as.factor(gender), family = binomial(link=logit), data=data)

To be sure we are on the same understanding, this is the same model as
one <- glm(Choice ~ gender, family = binomial(link=logit), data=data)

When gender is a string variable. R will make sure the interpretation is correct. Below I will omit the as.factor() function if reasonable to simplify the answer.
Model one is a simple model investigating the association between an outcome Choice and the gender gender. The coefficient estimate for gender, -0.340 indicates how much the probability of Choice=1 for males diverge (in this case decrease) from females. Of cause in this model we ignore any other variables that may influence the association between gender and Choice.
In conclusion, model 1 allow us to test and interpretant the crude relation between Choice and gender.
If you are not with me so far, try to look up simple models. Otherwise lets look at model 2.
two <- glm(Choice ~ treatment, family = binomial(link=logit), data=data)

Model 2 is very similar to model 1. Only this time instead of association between Choice and gender, we now look at the relation of Choice and treatment. The above should allow you to extend to this case.
So far so good, lets move to model 3.
three <- glm(Choice ~ treatment + gender, family = binomial(link=logit), data=data)

Say we are interested in the treatment effect on Choice, but we know that gender will affect both the Choice and treatment. Then gender is a so called confounder. I expect this is indirectly what you mean when you talk about imbalance. You expect that gender may influence the model result.
The output here will give an estimate for both gender and treatment. If we are only interested in the effect of treatment on choice, we would ignore the coefficient estimate for gender and only look at the estimate for treatment. Thus we can check if treatment has an effect on the choice, when correcting/adjusting for gender.
Are we on the other hand interested in the effect of gender, we would consider the estimate for gender and ignore the treatment effect. Thus we would get the effect of gender on choice when we correct for treatment.
I model 3 have no interaction-term, that is we assume that the treatment influence the choice in an equal manner for both men and women. Or vice versa if we switch treatment and gender.
So lets consider an interaction term. Model 4 is not actually reasonable because it only ad the cross term between gender and treatment but dont allow a separate effect. If this is new to you, I suggest you learn about interaction models. The internet should help you here.
The same goes for model 5. Since only one of the terms gender or treatment is allowed to have a separate effect.
So let's look at model 6.
six <- glm(Choice ~ gender*treatment, family = binomial(link=logit), data=data)

Model 6 is equivalent to the model
six <- glm(Choice ~ gender+treatment+gender:treatment, family = binomial(link=logit), data=data)

Shortly it asks the program to model the effect of treatment (or gender) on Choice when corrected for gender (or treatment) and the treatment(gender) effect is allowed to vary across levels of gender (treatment).
Forget interpretation of the value of the coefficients, this usually lead to confusion. Focus on the interaction term gender:treatment. If it influence the choice significantly, a cross effect exists.
This should also answer question 2)
3) Which variable/interaction, tells me whether the difference in treatment effect between men and women is significantly different? Do I need to run even another regression for this
The interaction term should tell you this.
Comment: I am sorry for the confusion. I was giving options. You can read it directly in `Male:as.factor(treatment)1 ` for model 6. You dont need another regression.
Comment: Thank you for completely making my day!
Comment: Kirsten, thank you so much for your very elaborate answer! It is enormously appreciated! I have only very few questions left. If I understand everything correctly, only regression six, properly accounts for the "imbalance" (the fact that I have much more females in the sample than males). Is that correct? For the last question, you say that the interaction of `male*treatment` tells me whether there is a significant difference between the treatment effect for men and women. Is this because the separate treatment effect only refers to the female subsample (this confuses me sometimes...
Comment: because it obviously just says `treatment`, which might "linguistically" suggest that it applies to the whole sample.
Comment: First, yes. Second, the interaction term treatment:gender in an ANOVA for binominal regression will tell you if the interaction term is significant. If yes, there is a significant difference in `treatment` effect on `Choice` across `gender`. If no the relation is non-significant. But yes you can also see it directly in the male*treatment in your table.
Comment: Okay, so to be clear, I DO need to run a separate test for this. It is not the effect on `Male:as.factor(treatment)1 ` in regression (6)? I have been googling, trying to find how to test an interaction in an ANOVA for binominal regression, but I am not really sure what to do exactly. Would you be willing to tell me how the r-code for such a test would look like?


Why do Guitar chords work the way they do compared to a Piano?

Question: I'm a Tabla (North Indian percussion instrument) player and I know just the basics of western music because I'm learning it bit by bit. I borrowed a Piano to learn music theory and it's going pretty good. My friend plays Guitar and we were jamming one day when I noticed how chords are played on a Guitar and it is confusing me to why they work.
So let's say I want to play the C major chord. On the piano I play the notes C, E and G together. But when my friend plays the same chord on his Guitar, he places his fingers on some frets and strums the Guitar. Now what bugs me is how he strums all 6 strings. And it doesn't matter which chord he plays, he will strum all 6 strings. What I don't understand is how can playing all 6 strings give the same result as playing just 3 notes on the Piano. Because to me, that's like playing some extra notes on the Piano.
Can anyone explain me why playing the open strings with the fretted ones on the Guitar gives the same result as just playing the notes on the Piano?
Comment: To add to Glorfindel's excellent answer, if you used both hands to play C major, it might make a bit more sense. With your right hand, play C, E, and G. Then with your left hand, just stretch out and play a C one octave below your right hand with your left thumb, and also the C an octave below that one with your left pinkie finger (fifth finger). Then you will be playing five notes on piano but still be playing a C major chord.
Comment: Not a full answer, but lots of chords don't end up with all 6 strings strummed. It's very common to only play 4-6 strings, either by skipping the first string or two on the strum, or by muting some strings with your fingers. And "power chords" are only 3 strings (which isn't technically a full triad, but is arguably still a "chord")
Comment: You seem to be confounded by the fact on a piano, each note needs a key  pressed. 3 notes = 3 keys pressed down. Whereas on guitar, open strings sometimes form part of the actual chord played. So when your guitarist only presses maybe 3 strings, the other 3 open ones are still in tune with the C chord. There are several ways to play open C on guitar. 032010; 332010; 032 013; 332013; x32010; x32013. All work, all are legit. Please read my answer, which hopefully explains what you are missing.
Answer: Yes, you're right, it is like playing some extra notes on the piano. Note that when your friend plays a C major chord, he probably plays 5 strings (but for other chords, e.g. the G major, it might be 6). The guitar strings will be playing the following notes: a middle C, a middle E, a middle G (the same notes as you are playing on the piano) plus a high C and a high E. You can play those last two notes on the piano as well with your other hand to hear the difference.
Due the nature of musical tones, whenever you play, say, a middle C, you hear not only the fundamental frequency of the middle C, but also higher harmonics, one of them being the high C. Therefore, higher tones will (usually) not change the 'essence' of the chord (but they can add to the 'richness').
Comment: Comments are not for extended discussion; this conversation has been [moved to chat](https://chat.stackexchange.com/rooms/79185/discussion-on-answer-by-glorfindel-why-do-guitar-chords-work-the-way-they-do-com).
Answer: I think that you haven't understood yet that to play a chord one has to play the notes of the chord but one is free to choose the order of the notes, if they are played high or low (one or several octaves up or down) and if some notes are doubled higher up or lower down.
All these changes define the 'voicing' of a chord. The chord is essentially still the same but it has a different character of 'colour'.
In a three note chord a guitarist plays the same note on different strings, but one or two octaves higher or lower. An experienced guitarist knows several different voicings of a chord. A pianist has an almost endless way to combine notes together in a chord-voicing.
Comment: Just to add to the complexity for the original question: Wouldn't it be true that if If two people played, with 20 fingers, 20 notes on a piano, and they were all either C, E, or G, that would still be a C major chord, just an unusual voicing? And, further, if *different instruments* play C, E, and G notes at the same time, they also form a chord, just one with different timbres within it.
Comment: Not a criticism of this excellent answer at all, but the term 'doubled' may make beginners in particular think that the same *note* gets played in other places, rather than an octave copy. Not sure even if there's a clearer term for this. And in actual fact, on guitar, there are chords which really do double up on particular notes, for specific effects and ease of fingering. On piano, obviously, this is obviated.
Comment: Another point of complexity, or lack of clarity, it is possible to mute strings, and it is possible to be playing open strings that are not in the chord but still sound good.  The OP did not really clarify all this.  Always playing "all strings" is a little ambiguous.
Comment: Yes, I know. That's why I wrote 'higher up or lower down'. Guitar chords are complex. I tried to focus on the main thing I thought the OP didn't understand yet.
Answer: Adding to the existing answers, but making it more personal to you. When your guitar playing friend plays his chords, try to find those particular notes, in their respective octaves, on your piano. You should be able to 'strum' them, and it'll sound remarkably like the chord he's playing, due to having the same voicing. Then you'll understand simply what is happening. Yes, sometimes he plays open notes in his strumming. Those notes will be part of the chord he's on, so will need no fingers pressing those strings down on certain frets.
Answer: To answer your question frankly, it does not work like that at all.  (or maybe sometimes).
So you need to be more explicit with your description of "all strings" and "fingers on some frets".
A major chord is the same on all instruments, it is the combination of 1, 3, 5 notes of the major scale.  If your friend fingered three and only three notes for a Gb major chord in standard tuning and played all strings it may sound really cool, but it would not sound like a Gb major chord.
The compatibility of the other strings with a given three note chord depends on a few factors.
1) we usually double notes, like the 1 and the 5.  Even in 4 voice harmony theory we are taught to double notes.  So if your friend is playing a bar chord in standard tuning then no harm no foul, all the notes are part of the chord.  For example, a Major chord in bar chord form is voiced (1, 5, 1, 3, 5, 1), spanning 2 octaves.  You have three occurrences of the 1 and 2 of the 5.  You can do this on the piano by the way.  Voicing refers to the ordering of notes.
2) if your friend and you are playing songs in a key that is referred to in guitar speak as "an open string key" (i.e. a key that is compatible with open string notes) then he/she can freely play open strings along with the notes of a chord and they will either be part of the chord or a compatible extension of the chord, so it will sound pleasing.
3) your friend may have tuned the guitar differently compared to standard tuning, allowing them to strum open strings as they play chords.
It is actually not typical for a guitarist to strum ALL strings even when playing in open string keys with open string chord forms.  A typical example is a dominant 7th chord.  The bar chord form is voiced (1, 5, 7, 3, 5, 1) using all 6 strings.  A more typical voicing in jazz is (1, x, 7, 3, 5, x) where x means don't play.  Now the guitarist can play the chord finger style with the right hand or "mute" the unwanted notes by gently draping the left hand fingers over the strings that should not be heard.  In this way they can appear to "strum" all strings but are really playing only the 4 they want.
So, in general one does not play all the strings all the time, but you can see that in some cases it's okay.  Those cases are limited and it is no surprise that much of classical guitar music (or guitar music in general) is written in what I call open string keys (hence, my comment maybe sometimes).  Jazz guitarists get used to playing in Bb and Eb which do not lend themselves to open string voicing (at least not easily and not over a large number of chords in the key).
Comment: Comments are not for extended discussion; this conversation has been [moved to chat](https://chat.stackexchange.com/rooms/79186/discussion-on-answer-by-ggcg-why-do-guitar-chords-work-the-way-they-do-compared).
Comment: There seems to be a progression, among guitarists at least, from thinking of chords as shapes that you slap down on the fingerboard and strum, to thinking of harmony as a concept that you express through note choices and placement. For jazz guitarists, chord-melody seems helpful in this regard. Having not gone through a rigorous classical guitar training, I wonder if classical guitarists arrive at the better end of this spectrum more quickly....
Comment: That is an interesting observation.  My Jazz instructor would describe voicing and chord melody as a string of shapes "The triangle moves to the diagonal to the diamond then another diagonal".  He was a trip and exceptional at chord melody.  Classical training does not typically emphasize progressions but pieces.  If music is well structured then you have good movement from one chord to another following harmony theory.  So I guess you are learning by example, It could go either way.
Answer: imagine he plays piano with 3 notes on one hand, and those same three notes an octave higher with the other hand, then it's similar to what's happening on guitar - as guitar strings span 2 octaves.  It's the same 3 notes (e.g. C, E, G) just in different pitches.
Answer: Because the guitar is being tuned in 'open tuning':
(low) EADGBE (high)
When he does a Cmaj, 'open' position, fretting the A,D, and B string the notes become:
(low) ECEGCE (high)
He could optionally also add third fret on the low E string (G note) to have:
(low) GCEGCE (high)
... both of which are Cmaj, C-E-G.
If by chance you're actually asking how do six strings sound 'at once' it's because the time between the start of each up or down strum motion is quite quick. 120 beats per minute, one down-up strum per beat, means 240 swipes a minute, a quarter-second each.
And one can certainly play more than three keys at once on the piano.
Comment: In my experience playing folk guitar, C/E (C chord with a low E) is very rare, but people in this thread keep mentioning it. Is it more common in other genres?
Comment: @wjandrea: For what it's worth, I've always heard that playing C/E instead of C is a common beginner mistake. Every teacher I know tries to correct it ASAP and tells the student to only let 5 strings ring for open C and 4 strings for open D.
Comment: @wjandrea FWIW I agree with Eric and would add that there's no real reason to even mention the C/E chord on questions addressed to beginners like this. They'll learn about slash chords when they need to.
Comment: Thank you for that ... I've forgotten C/E is an inversion as I've been playing C/G.
Answer: Can't comment directly, but here are some points:
"Folk" guitarists will often just strum across all strings and thus play "extra" notes, but this is not universal.  Sometimes a guitarist will mute strings by pressing lightly on strings that may be strummed but should not sound, and/or simply not strum those strings.
For jazz guitarists this is pretty much the default -- they tend to mute and/or not strum strings that they don't want to sound -- and with "jazz" chords (maj7b5) it's especially important, because the player is trying to create a very specific sound with specific harmonies.
All of the above of course assumes use of a pick (plectrum).
Fingerstyle guitarists have it much easier in this regard, since they can pluck (not strum) only the strings they want.  (Of course, this means they can pluck at most five strings - if they want all six then it's back to strumming).
Comment: Or a finger from the left hand plucking the sixth string above the fretboard.


Diferença de performance e situação de uso de tipos numéricos

Question: Gostaria de saber a diferença entre os tipos Long, Double, Float, Decimal e Int, levando em consideração de quando é o melhor uso em casos reais. Ex: "usa float em juros pois é...". E também a diferença de performance entre elas. Ex: "int tem performance melhor que long pois..."
Acho que é bem valida a pergunta, levando em consideração que muitas vezes usamos errado em nosso dia a dia, e por minima diferença de performance faça, é sempre interessante pensarmos nisso.
Answer: No .Net (assim como em várias outras linguagens), existe uma separação entre tipos inteiros e tipos racionais, então vou separar minha explicação desses tipos nessas duas categorias.
Tipos Inteiros
Existem vários tipos inteiros, novamente podem ser separados em dois grupos, os que aceitam valores negativos, e os que não aceitam valores negativos.
Aceitam Negativos (possuem sinal): Int32 é o mais comum, mas temos outros: Int16, Int64 (não existe Long, mas sim o alias long no C#, que é o mesmo que Int64) e SByte.
│ Tipo  ║ Bits ║           Mínimo           ║            Máximo         ║ Alias C# ║ Literal │
╞═══════╬══════╬════════════════════════════╬═══════════════════════════╬══════════╬═════════╡
│ SByte ║  8   ║ -128                       ║ 127                       ║  sbyte   ║         │
│ Int16 ║  16  ║ -32768                     ║ 32767                     ║  short   ║         │
│ Int32 ║  32  ║ -2.147.483.648             ║ 2.147.483.647             ║  int     ║    0    │
│ Int64 ║  64  ║ -9.223.372.036.854.775.808 ║ 9.223.372.036.854.775.807 ║  long    ║    0L   │
└───────╨──────╨────────────────────────────╨───────────────────────────╨──────────╨─────────┘

As letras que aparecem nos literais, podem ser maiúsculas ou minúsculas: 0L é o mesmo que 0l.
Aceitam valores positivos apenas (sem sinal):
│ Tipo   ║ Bits ║ Mínimo ║            Máximo          ║ Alias C# ║ Literal │
╞════════╬══════╬════════╬════════════════════════════╬══════════╬═════════╡
│ Byte   ║  8   ║   0    ║ 255                        ║  byte    ║         │
│ UInt16 ║  16  ║   0    ║ 65535                      ║  ushort  ║         │
│ UInt32 ║  32  ║   0    ║ 4.294.967.295              ║  uint    ║   0U    │
│ UInt64 ║  64  ║   0    ║ 18.446.744.073.709.551.615 ║  ulong   ║   0UL   │
└─────═──╨──────╨────────╨────────────────────────────╨──────────╨─────────┘

As letras que aparecem nos literais, podem ser maiúsculas ou minúsculas: 0UL é o mesmo que 0ul.
Em termos de uso desses tipos, não há grande diferença de performance no uso de variáveis locais ou parâmetros de métodos. Geralmente se usa o tipo Int32 (int) para esses usos, a não ser que os valores esperados excedam os limites do int, em cujo caso se usa Int64 (long).
Já o Byte (byte) só é usado mesmo para trabalhar com dados binários, nunca vi sendo usado em códigos que não sejam com este fim.
Os outros tipos, geralmente só são usados em estruturas de dados struct ou class muito longas, ou então em arrays, de forma que ocupem menos memória... mas isso só faria sentido mesmo em estruturas muito usadas, ou em arrays muito grandes mesmo, da ordem de milhões ou até mesmo bilhões de itens.
Além de tudo isso, vejo os tipos sem sinal (aqueles que só aceitam positivos) serem usados em operações bit-a-bit (chamadas comumente de bitwise), pela facilidade de se trabalhar com todos os bits dos mesmo, o que é mais difícil quando há o bit de sinal.
Tipos Racionais
Há apenas 3 desses no .Net: Single, Double e Decimal.
│   Tipo   ║     Single    ║      Double               ║      Decimal                            │
╞══════════╬═══════════════╬═══════════════════════════╬═════════════════════════════════════════╡
│ Alias C# ║     float     ║      double               ║      decimal                            │
│ Mínimo   ║ -3.402823e+38 ║  -1.7976931348623157e+308 ║ -22.214.171.1244.264.337.593.543.950.335 │
│ Máximo   ║  3.402823e+38 ║   1.7976931348623157e+308 ║  184.108.40.2064.264.337.593.543.950.335 │
│ Literal  ║    0f         ║   0.0  ou  0d             ║     0m                                  │
│ Base Exp.║    2          ║    2                      ║     10                                  │
└──────────╨───────────────╨───────────────────────────╨─────────────────────────────────────────┘

As letras que aparecem nos literais, podem ser maiúsculas ou minúsculas: 0M é o mesmo que 0m.
Os tipos de base 2 (Single e Double), são operados por instruções do próprio processador, em uma
unidade chamada de FPU (floating-point unit)... e que nos processadores atuais
são tão otimizados, que as operações matemáticas com pontos flutuantes chegam
a ser tão rápidas quanto com tipos inteiros.
Os tipos Single e Double são usados quando não há de se ter correspondência
exata com números decimais em uma fração. Exemplos: cálculos que envolvem a
física, usadas na engenharia ou nas simulações feitas em jogos, usam estes tipos.
Em termos de performance os tipos Single e Double são iguais nas máquinas
atuais, pois a FPU converte ambos internamente para 80-bits. Então a única vantagem
real em se usar Single é em termos de uso de memória.
O tipo Decimal existe para dar suporte a operações que devem ter correspondência
exata com frações decimais do mundo real, com quando trabalhando com valores
monetários... inclusive, acho que o M do literal vem de money (mas isso eu estou
especulando).
O tipo Decimal possui 128 bits, dos quais 96 são usados para representar o valor interno
chamado de mantissa, e os outros são usados para indicar um divisor de base 10...
é praticamente um expoente, igual o que existe para os de base 2, só que na base 10
e apenas negativos. Portanto, o Decimal não é capaz de representar números
tão grandes como o Single e o Double (pois esses dois aceitam expoentes positivos).
Em compensação, o tipo Decimal possui uma precisão absurdamente maior.
Em termos de performance, o tipo Decimal é muito ruim, se comparado aos tipos
de base-2, pois todas as operações matemáticas são feitas na ALU (Arithmetic logic unit),
e por isso são subdivididas em várias estapas de cálculos independemente da operação
sendo feita.
Answer: Basicamente precisão é a grande diferença entre eles:
Float: 7 Digitos (32 bit)
Double: 15-16 Digitos (64 bit)
Decimal: 28-29 Digitos (128 bit)
Decimais (decimal) tem muito mais precisão do que qualquer um dos outros, utilizado quase na totalidade das aplicações financeiras que requerem um grande grau de precisão. Em contra partida os Decimais (decimal) são muito mais lentos (chegando a 20x) do que double/float.
Comment: Acredito que `Decimal` tenha mais precisão não apenas pelos bits extras, mas porque não é implementado como [ponto flutuante](http://pt.wikipedia.org/wiki/Ponto_flutuante), que por definição tem problemas para representar certos números. Provavelmente também é por isso que Decimal é mais lento.
Comment: @bfavaretto: o tipo Decimal no .Net é ponto-flutuante, só que o expoente está sobre uma base decimal ao invés de binária - ver: [Decimal Structure](http://msdn.microsoft.com/en-us/library/system.decimal(v=vs.110).aspx).
Comment: Essa referência é bem interessante para ver a diferença entre decimal e float: http://gregs-blog.com/2007/12/10/dot-net-decimal-type-vs-float-type/
Comment: @MiguelAngelo Interessante, eu não sabia disso! Na verdade, sei muito pouco do .Net, por isso usei "acredito" e "provavelmente"... Obrigado pela informação.
Comment: @bfavaretto: Disponha... minha intensão foi de informar mesmo, não de criticar nem nada. Mesmo você tendo dito "acredito", imaginei que algumas pessoas pudessem tomar o dito como fato. =D
Comment: Tranquilo, @Miguel. Eu não achei que você estava criticando, e sempre fico feliz de aprender algo novo :) De fato o que você acrescentou será útil pra muita gente.


How to get Node IDs of nodes whose titles contain a certain string?

Question: I'm trying to get a list of nodes whose titles contain a given string, in this case the term name of a term attached to another node.
Based on other answers I've found online, I've thought this could work:
$sql = 'SELECT title FROM {node} WHERE title LIKE :title';
$result = db_query($sql, array(':title' => '%' . db_like($term->name)));

That's giving me a response but it's all empty, which makes no sense.
Here's what the response looks like:
DatabaseStatementBase Object
(
[dbh] => DatabaseConnection_mysql Object
    (
        [needsCleanup:protected] =>
        [target:protected] => default
        [key:protected] => default
        [logger:protected] =>
        [transactionLayers:protected] => Array
            (
            )

        [driverClasses:protected] => Array
            (
                [SelectQuery] => SelectQuery
                [MergeQuery] => MergeQuery
                [UpdateQuery] => UpdateQuery
                [DatabaseSchema] => DatabaseSchema_mysql
            )

        [statementClass:protected] => DatabaseStatementBase
        [transactionSupport:protected] => 1
        [transactionalDDLSupport:protected] =>
        [temporaryNameIndex:protected] => 0
        [connectionOptions:protected] => Array
            (
                STUFF
                    (
                        [default] =>
                    )

            )

        [schema:protected] => DatabaseSchema_mysql Object
            (
                [connection:protected] => DatabaseConnection_mysql Object
*RECURSION*
                [placeholder:protected] => 0
                [defaultSchema:protected] => public
                [uniqueIdentifier:protected] => 5670ef6385b8e5.94304345
            )

        [prefixes:protected] => Array
            (
                [default] =>
            )

        [prefixSearch:protected] => Array
            (
                [0] => {
                [1] => }
            )

        [prefixReplace:protected] => Array
            (
                [0] =>
                [1] =>
            )

    )

[queryString] => SELECT * FROM node WHERE title LIKE :title
)

Do I need to do something like this using CONTAINS instead?
$sql = 'SELECT title FROM {node} WHERE CONTAINS(title, :title)';
$result = db_query($sql, array(':title' => '%' . db_like($term->name)));

Answer: You need iterate over the node collection, you can use this code to do so:
$sql = 'SELECT title FROM {node} WHERE title LIKE :title';
$result = db_query($sql, array(':title' => '%' . $term->name . '%'));

foreach($result as $node) {
    //dpm($node);
    //$node is your object
    echo $node->title . '
';
}

Edit: If you want only specifics content types use this:
$sql = "SELECT title FROM {node} WHERE title LIKE :title AND type = 'your_content_type'";

Comment: Hey, this works! So I was encoding the term incorrectly by leaving off the trailing %?  Ugh.  That seems pretty obvious now.
Comment: @rexfaraday a pleasure help you, good luck with your project ;-)
Comment: If I wanted to filter my results to just a specific content type, would I add a condition to the first line of the snippet?
Comment: @rexfaraday I edit my answer, see it
Comment: Are the ' 's in the right place in the edit?
Comment: @rexfaraday I edit again, see now


Getting a "diff" of two different OSCAP releases?

Question: I am trying to get a "diff" of the commands that are executed as part of applying different releases of the oscap-anaconda-addon, specifically the STIGs applied in RHEL 7.9 and in AlmaLinux 9.1.
Context: We have a security appliance that was originally based on RedHat 7.9 and are migrating it to AlmaLinux 9.1. There has been a lot of "empirical discovery" so far as we run into configuration differences between the two platforms.
Most of these we can resolve fairly readily, but the OSCAP differences are opaque, given that they are ultimately based on differences in the underlying openscap packages, which are complex.
Ideally, I'd like to know what remediation commands are run by the add-on for each release. I'd be happy with some direction that would allow me to write a program that parses different versions of openscap using an appropriate "key" and returns the list of mitigation commands, which I could then compare.
Apologies if this is the wrong forum, I've been trying to determine the best place to pose this question, but haven't had much luck (the oscap anaconda add-on mailing list, e.g., has very little traffic and the last few Qs remain unanswered).
Any and all guidance will be warmly received! Thank you!
Answer: Explore
$ oscap xccdf generate fix --help

You will have to run this twice for each target. First time get the shell scripts applied to the system, second time to get oscap-anaconda-addon fixes.


How to refresh WPF chart after updating the Y Axis Maximum value?

Question: I 'm creating a Line chart using WPFToolKit.
The chart comes up fine but i want to change the Maximum property of the Y Axis upon button click of a modal window after loading the chart for the first time. And the chart should be refreshed with the updated Y Axis Max value
Below line shows how Chart is defined in xaml.
<DVC:Chart Canvas.Top="80" Canvas.Left="10" Name="mcChart" VerticalAlignment="Stretch"/>

I'm calling below code in windows.xaml.cs constructor and it is setting Y-Axis Max to 200
mcChart.Axes.Add(new LinearAxis()
        {
            Minimum = 0,
            Maximum = YMax > 0 ? YMax : 200,
            Orientation = AxisOrientation.Y,
            ShowGridLines = true,
        });

        mcChart.UpdateLayout();

How can i change the Y-Axis Max value from a modal window's button click event and refresh chart to display with new YMax.
I'm not sure if i have to do something with RegisteredListeners.
I'm new to WPF and any help is appreciated!
Please note that i'm looking to achieve this from the C# code behind and not in xaml.
Thanks,
Sujay
Comment: The modal window differs from  the main window and it doesn't have access to the chart, right? I would solve this problem using  an  user-defined event. Or I would change  the max value after closing of the modal window. It depends on a task.
Comment: ok, forget about the modal window. Basically i'm looking for how to change the max value and refresh the chart. i can handle about when and where to call that logic. Thanks Sujay
Comment: @user647204 Updates will be reflected automatically because the Maximum property is a dependency property. Some day you will be familiar with them, but now just know that you can set a value to a property without calling update functions.
Answer: If you have access to the chart, you can find the neccessary axis and change the Maximum property without updating layout. Here is an example with a linear Y axis:
var yAxis = this.mcChart.ActualAxes.OfType<LinearAxis>().FirstOrDefault(ax => ax.Orientation == AxisOrientation.Y);
if (yAxis != null)
    yAxis.Maximum = 300;

The complete version of this example:
MainWindow.xaml
<Grid>
    <Grid.RowDefinitions>
        <RowDefinition Height="20"/>
        <RowDefinition Height="*"/>
    </Grid.RowDefinitions>
    <Button Content="Set max value = 300" HorizontalAlignment="Center" Click="Button_Click"/>
    <charting:Chart Grid.Row="1" x:Name="mcChart">
        <charting:Chart.Series>
            <charting:LineSeries ItemsSource="{Binding LineItems}" IndependentValuePath="Date" DependentValuePath="Value"/>
        </charting:Chart.Series>
    </charting:Chart>
</Grid>

MainWindow.xaml.cs
public partial class MainWindow : Window
{
    public MainWindow()
    {
        InitializeComponent();

        //Add a linear Y axis
        int YMax = 150;
        mcChart.Axes.Add(new LinearAxis()
        {
            Minimum = 0,
            Maximum = YMax > 0 ? YMax : 200,
            Orientation = AxisOrientation.Y,
            ShowGridLines = true,
        });

        //Create and set a view model
        var items = Enumerable.Range(0, 50).Select(i => new ChartItemModel { Date = new DateTime(2010, 1, 1).AddDays(i), Value = 30 + i }).ToList();
        this.DataContext = new MainViewModel { LineItems = items };
    }

    //Set Maximum=300
    private void Button_Click(object sender, RoutedEventArgs e)
    {
        var yAxis = this.mcChart.ActualAxes.OfType<LinearAxis>().FirstOrDefault(ax => ax.Orientation == AxisOrientation.Y);
        if (yAxis != null)
            yAxis.Maximum = 300;
    }
}

public class MainViewModel
{
    public List<ChartItemModel> LineItems { get; set; }
}

public class ChartItemModel
{
    public DateTime Date { get; set; }
    public double Value { get; set; }
}