Contact info requirement after 5 minutes

Question: I have a PHP site that the client would like to require the viewer to fill out and submit a contact form after viewing the site for 5 minutes.  Info does not need to be added to a database, just sent to their office email. I have created the form but am not sure of the best way to handle the pop-up and make it required before continuing to view the site.
Comment: Make it *required*? What a way to ensure all your visit lengths are < 5 minutes.
Comment: @Matt I get even more stupid requirements at my work :P
Comment: I suppose you could track a session value.  Set it to the current timestamp when a session starts, compare it to the current timestamp on every page request.  If the comparison exceeds 5 minutes, redirect to the form.  It's... not a very good user experience.  But I guess that's the problem of whoever defined the requirement.
Comment: And, it would be very easy to get around that kind of requirement without server-side intervention (simply reset the session by closing the browser). This kind of functionality also means that if a user returns to the site, they would have to re-enter their information after 5 min even if they already did previously. Very odd requirement. How do you handle javascript being turned off?
Answer: You're doing your client a significant disservice if you haven't tried to talk them out of this. If they want people not to visit the site, they should just not have it developed. If they want people to visit it (or ever come back) they shouldn't even consider this.
That being said, you could set up some sort of timer to "force" a popup to appear, but many popup blockers would handle that. There would be ways around any scheme like this, regardless of how you do it (cookies, serving a different page, etc.), but unless you've got something incredibly unique on that site, your client's readers probably won't even bother with them-they'll go to a site that isn't deliberately broken.
I would suggest to your client that they instead put in a box where users who WANT to be contacted can enter an email address. That won't annoy your users, but will still let you take in leads from those who are interested.
Comment: Love it - I totally agree - that's what I had been telling my client all along - glad to hear you are all backing me up. We'll see how it works out and thanks for the suggestions!
Answer: This may help you;
PHP for the website page
if (false === isset($_SESSION['startTime'])) {
     $_SESSION['formSubmitted'] = false;
     $_SESSION['startTime'] = time();
}

PHP for the jqueryCheck.php;
$return = 0;

if (false == $_SESSION['formSubmitted']) {
    if ((time() - $_SESSION['startTime']) > 300) {
        $showForm = 1;
    }
} else {
    $return = 2;
}

echo $return;

PHP after form submitted and validated
$_SESSION['formSubmitted'] = true;

JQUERY
var intervalId = setInterval(function(){
    $.ajax({ url: "jqueryCheck.php", success: function(showForm){
        switch (showForm) {
             case 0: //not yet at 5 mins and not submitted
             break;
             case 1:  //at 5 minutes no form submitted
                //code to show form
             break;
             case 2:  //form submitted
                 clearInterval ( intervalId );
             break;
        }
    }});
}, 60000);

Answer: This is a simply solution without Javascript.
if (!isset($_SESSION['trial_end'])) {
    $_SESSION['trial_end'] = time() + 5 * 60;
}

// Check if trial has expired and we are not already on the form
if (time() > $_SESSION['trial_end'] && $_SERVER['REQUEST_URI'] !== '/form') {
  header('Location: /form');
  exit;
}


What are different types of serve strategies in squash?

Question: I am quite new to playing squash.
As I watch professional matches on YouTube,
I notice quite a few different types of serves.
As the title states,
what are the different types of serve strategies in squash?
Answer: Serve strategies are used to gain advantage over an opponent. A lob will hit the front wall high and central, and will take the ball over head to the back of the opponents half.
If a player returns this type of serve easily then a change of serve tactic may be used. Eg, A smash or power serve.  This is when the server serves the ball with a powerful smashing action. It is aimed to hit just above the service line at center or off center.  The ball will come very fast and lower down at a steeper angle. Depending where it strikes the wall, it may come directly at the opponent or to their left.
Another type is to hit front wall at an angle, causing the ball to then deflect off the side wall towards the opponent. This forces the opponent to change or alter stance to return the serve, giving a possible advantage.
There are other variations, but it is always a good idea to vary your serves so as not to become predictable.


Delay sending an email via EWS leaves mail in sent-items without actually sending it

Question: I'm trying to delay-send an email through EWS (Exchange 2019) from a Word VBA module. This works fine, as long as I send immediately. As soon as I add the element for delayed send
<t:ExtendedProperty>
  <t:ExtendedFieldURI PropertyTag="16367" PropertyType="SystemTime" />
  <t:Value>2022-01-01T00:00:00.000</t:Value>
</t:ExtendedProperty>

The mail goes into sent items immediately and does not get delivered. This is the entire code - the XML is below for better readability:
Private Sub SendEMail()
  Dim sReq As String
  Dim xmlMethod As String
  Dim XMLreq As New MSXML2.XMLHTTP60
  Dim EWSEndPoint As String

  Dim t As String
  t = "2022-01-01T00:00:00.000"

  EWSEndPoint = "https://myexchange/EWS/Exchange.asmx"
  sReq = "<?xml version=""1.0"" encoding=""UTF-8""?>" & vbCrLf & _
          "<soap:Envelope xmlns:soap=""http://schemas.xmlsoap.org/soap/envelope/"" xmlns:t=""http://schemas.microsoft.com/exchange/services/2006/types"">" & vbCrLf & _
            "<soap:Header>" & vbCrLf & "<t:RequestServerVersion Version=""Exchange2016""/>" & vbCrLf & "</soap:Header>" & vbCrLf & _
            "<soap:Body>" & vbCrLf & _
              "<CreateItem MessageDisposition=""SendAndSaveCopy"" xmlns=""http://schemas.microsoft.com/exchange/services/2006/messages"">" & vbCrLf & _
                "<SavedItemFolderId>" & vbCrLf & _
                  "<t:DistinguishedFolderId Id=""sentitems"" />" & vbCrLf & _
                "</SavedItemFolderId>" & vbCrLf & _
                "<Items>" & vbCrLf & _
                  "<t:Message>" & vbCrLf & _
                    "<t:ItemClass>IPM.Note</t:ItemClass>" & vbCrLf & _
                    "<t:Subject>" & "123 " & Now() & " für " & t & "</t:Subject>" & vbCrLf & _
                    "<t:Body BodyType=""Text"">" & "body" & "</t:Body>" & vbCrLf & _
                    "<t:ExtendedProperty>" & vbCrLf & _
                      "<t:ExtendedFieldURI PropertyTag=""16367"" PropertyType=""SystemTime"" />" & vbCrLf & _
                      "<t:Value>" & t & "</t:Value>" & vbCrLf & _
                    "</t:ExtendedProperty>" & vbCrLf & _
                    "<t:ToRecipients>" & vbCrLf & _
                      "<t:Mailbox>" & vbCrLf & "<t:EmailAddress>" & "myemail" & "</t:EmailAddress>" & vbCrLf & "</t:Mailbox>" & vbCrLf & _
                    "</t:ToRecipients>" & vbCrLf & _
                  "</t:Message>" & vbCrLf & _
                "</Items>" & vbCrLf & _
              "</CreateItem>" & vbCrLf & _
            "</soap:Body>" & vbCrLf & _
          "</soap:Envelope>" & vbCrLf

  xmlMethod = "POST"
  XMLreq.Open xmlMethod, EWSEndPoint, False, "myusername", "mypassword"
  XMLreq.setRequestHeader "Content-Type", "text/xml; charset=""UTF-8"""
  XMLreq.Send sReq

  If XMLreq.Status = 200 Then
                    ' Message Sent okay
                    MsgBox ("ok")
  Else
                    ' Something went Wrong
                    MsgBox ("error")
  End If
End Sub

And here's the XML:
<?xml version="1.0" encoding="UTF-8"?>
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:t="http://schemas.microsoft.com/exchange/services/2006/types">
<soap:Header>
<t:RequestServerVersion Version="Exchange2016"/>
</soap:Header>
<soap:Body>
<CreateItem MessageDisposition="SendAndSaveCopy" xmlns="http://schemas.microsoft.com/exchange/services/2006/messages">
<SavedItemFolderId>
<t:DistinguishedFolderId Id="sentitems" />
</SavedItemFolderId>
<Items>
<t:Message>
<t:ItemClass>IPM.Note</t:ItemClass>
<t:Subject>123 31.03.2021 13:35:19 für 2022-01-01T00:00:00.000</t:Subject>
<t:Body BodyType="Text">body</t:Body>
<t:ExtendedProperty>
<t:ExtendedFieldURI PropertyTag="16367" PropertyType="SystemTime" />
<t:Value>2022-01-01T00:00:00.000</t:Value>
</t:ExtendedProperty>
<t:ToRecipients>
<t:Mailbox>
<t:EmailAddress>myemail</t:EmailAddress>
</t:Mailbox>
</t:ToRecipients>
</t:Message>
</Items>
</CreateItem>
</soap:Body>
</soap:Envelope>

I am in Europe here, so 24-hour-timeformat. To avoid any hazzle with time and date formatting, I have taken a simple day in the example, but that did not make any difference. I've tried past and future dates, no change: The mail goes to sent items immediately and does not send. (The xmlreq.send-lines always closes without error.) As soon as I remove the four extendedproperty-lines, it sends without problems.
What is it that I'm overlooking?
Answer: Remove the SavedFolderId it's optional anyway but when i test your XML with it I see the same problem so

<?xml version="1.0" encoding="UTF-8"?>
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:t="http://schemas.microsoft.com/exchange/services/2006/types">
<soap:Header>
<t:RequestServerVersion Version="Exchange2016"/>
</soap:Header>
<soap:Body>
<CreateItem MessageDisposition="SendAndSaveCopy" xmlns="http://schemas.microsoft.com/exchange/services/2006/messages">
<Items>
<t:Message>
<t:ItemClass>IPM.Note</t:ItemClass>
<t:Subject>123 31.03.2021 13:35:19 für 2022-01-01T00:00:00.000</t:Subject>
<t:Body BodyType="Text">body</t:Body>
<t:ExtendedProperty>
<t:ExtendedFieldURI PropertyTag="16367" PropertyType="SystemTime" />
<t:Value>2021-03-31T23:06:00.000</t:Value>
</t:ExtendedProperty>
<t:ToRecipients>
<t:Mailbox>
<t:EmailAddress>firstname.lastname@example.com</t:EmailAddress>
</t:Mailbox>
</t:ToRecipients>
</t:Message>
</Items>
</CreateItem>
</soap:Body>
</soap:Envelope>

works okay for me, It does save the message temporary to the drafts folder (instead of the outbox) but once sent the message does end up in the SentItems Folder.
Comment: Thank you, Glen, it really works fine without the SavedFolderId. For the record: I have played a bit and left SavedFolderId in the XML and changed it to outbox. This put the messages in the outbox as expected, but future messages did not get delivered at all from there and messages with a past date did get delivered, but remained in the outbox. So I have now removed the code again and it works fine, although through drafts. If someone finds the source of this (cosmetic) error, I'll be entirely happy :-)


Conceptual explanation of regression coefficient?

Question: I understand, mathematically, how to get the estimates of coefficients in ordinary least squares. What I am struggling with is coming up with a conceptual, geometric explanation for the correlation part of the simple linear regression coefficient.
Say we have the following equation:
$$
y = \hat\beta_1x + \hat\beta_0
$$
where
$$
\hat\beta_1 = \frac{S_{xy}}{S^2_x} = r_{xy}\frac{S_y}{S_x}
$$
and
$$
\hat\beta_0 = \overline{y} - \hat\beta_1\overline{x}
$$
If I understand correctly, we are essentially just getting estimates of spread ($\hat\beta_1$) and position ($\hat\beta_0$) shifts that can turn $x$ into $y$ as best as possible (least squares). So from what I understand, the ratio of standard deviations ($\frac{S_y}{S_x}$) makes it so $x$ has the same spread as $y$, and then the estimate of $\beta_0$ moves $x$ to the same position as $y$.
What I am missing is what the correlation $r_{xy}$ is doing in this linear transformation. If we have shifted the spread and position of $x$ as above, what is $r_{xy}$ representing?
Answer: $r_{xy}$ is the slope of the OLS regression line in that transformed space.  You can also think of $r^2_{xy}$ as the proportion of the variance in the transformed $y$ variable that is explainable by virtue of knowledge of the transformed $x$, and $1-r^2_{xy}$ as the error variance, or the variance that cannot be so explained.
Comment: Oh wow okay that makes total sense - I don't know why I couldn't get there. Thanks!


Relationship of x regress y and y regress x on the slope

Question: Consider a linear regression model y on x and x on y. We have
$Y = a'X + a$ where $a' = \frac{cov(X,Y)}{Var(X)}$. Equivalently, we have $X = b'Y+b$ where $b' = \frac{cov(X,Y)}{Var(Y)}$. I am interested in the relationship between $a'$ and $b'$
Clearly, if $Var(X) = Var(Y)$ then we have $a'=b'$. However, say we want $a' = \frac{1}{b'}$. It follows that:
\begin{aligned}
a' &= \frac{1}{b'} \\
\frac{cov(X,Y)}{Var(X)} &= \frac{Var(Y)}{cov(X,Y)} \\
\frac{1}{Var(X)} &= Var(Y)
\end{aligned}
Ok. What about this example then, where
\begin{aligned}
y &= 2x \\
\frac{1}{2}y &= x \\
&\text{but} \\
Var(Y) &= 4Var(X) \\
\end{aligned}
Clearly we have $a' = \frac{1}{b'}$ but our variances are not inverses of one another. Where is my understanding faulty?
Answer:
you are wrong in third line.  cov(x,y) won't get cancel out. It will be squared.
Comment: I am a fool! Thank you. Does it hold then that $a' = \frac{1}{b'}$ whenever $cov(x,y) != 0$?
Comment: yes it is. cov(x,y) == 0 means that they don't have any relationship thus can't draw any regression line between them.


How to concatenate structs in a loop in python

Question: I am trying to search for all users in an sql database whose first names are "blah" and return that data to my html through an ajax call. I have this functioning with a single user like this:
user = db.execute(
            'SELECT * FROM user WHERE genres LIKE ?', (str,)
        ).fetchone()
        user_details = {
            'first': user['first'],
            'last': user['last'],
            'email': user['email']
        }
        y = json.dumps(user_details)
        return jsonify(y)

Now for multiple users I want the struct to look something like this:
users{
    user1_details = {
        'first': user['first'],
        'last': user['last'],
        'email': user['email']
    }
    user2_details = {
        'first': user2['first'],
        'last': user2['last'],
        'email': user2['email']
    }
    user3_details = {
        'first': user3['first'],
        'last': user3['last'],
        'email': user3['email']
    }
}

generating each user_details in a loop. I know I can use fetchall() to find all the users, but how do I concatenate the details?
Answer: Fetch all the rows after the query, then structure the results as you'd like.
Example:
   db = mysql.connection.cursor()

   # query
   db.execute('SELECT * FROM user')

   # returned columns
   header = [x[0] for x in db.description]

   # returned rows
   results = db.fetchall()

   #data to be returned
   users_object = {}

   #structure results
   for result in results:
        users_object[result["user_id"]] = dict(zip(header,result))

   return jsonify(users_object)

As you can see in under "#structure results", you just loop through the results and insert the data for each row into the users_object with key equal to "user_id" for example.
If you want the results in an array just convert users_object into an array e.g. users_array and append the dict to the array within the loop instead
Comment: Yes, this is exactly what I was looking for. Thanks.
Answer: The keys in the desired users dictionary do not seem particularly useful so you could instead build a list of user dicts. It's easy to go directly from fetchall() to such a list:
result = db.execute('SELECT * FROM user WHERE genres LIKE ?', (str,))
users = [{'first': first, 'last': last, 'email': email} for first, last, email in result.fetchall()]
return jsonify(users)

To return a dict containing the user list:
return jsonify({'users': users})


Checking cache control max age setting in firefox

Question: Firefox has a cool feature which allows me to check the cache.
I simple type
<code>about:cache
</code>
in the address bar and some useful cache information appears. This includes every file cached and its expires time.  However, I don't know if firefox is getting this information from the expires header or the cache control header or just obeying HTTP 1.1 which states that if both are set the cachc control max age header wins?
Any tips?
Answer: Firefox is just following HTTP 1.1 here: max-age, then expires, then the suggested heuristic, in that order.


Programatically remove field content from all nodes where content equals 'string'?

Question: I am doing a migration from D7 to D8. Due to various issues in the initial site, I am doing content migration through CSV import rather than the direct drupal to drupal migration that's built in.
My content type has a Video Embed Field in it, which was throwing errors on migration unless it was filled. As such, I had to throw in a placeholder video URL for all nodes that didn't have the node filled.
Is there a way to (within drupal, or via a SQL query) programatically remove the field content from all nodes where the url is "youtube.com/myPlaceholderVideo"? All the content is in, but now I'm stuck with ~450 nodes with this placeholder URL.
Answer: The video_embed_field module adds a simple field based on whatever you named it.  So if your field is named "field_youtube_embed_test", you'd get a field on your content type that is a standard drupal field, with a table "node__field_youtube_embed_test" and a revision table "node_revision__field_youtube_embed_test".  You can run a query to delete all entries based on bundle as that is one of the columns on both tables.  So you can run a query for each.
DELETE from node__field_youtube_embed_test where field_youtube_embed_test_value = 'youtube.com/myPlaceholderVideo' and bundle = 'article';

DELETE from node_revision__field_video_embed where field_youtube_embed_test_value = 'youtube.com/myPlaceholderVideo' and bundle = 'article';

Or if you want to delete everything from those tables, you just use the truncate command:
TRUNCATE node__field_youtube_embed_test;

TRUNCATE node_revision__field_video_embed;

Using a query works for simple fields such as textfields, booleans, etc, but it doesn't work for more complex structures such as field collections or paragraphs.  For those, you would probably want to iterate through them programmatically and unset the value and then save the node.
Comment: Thanks for the suggestion. Are those the only places with any reference to the field value? Because I tried deleting a single line from each of those tables yesterday, but the value still seemed to be showing up when I went to edit the node.
Comment: Nodes are cached, so you'll need to clear the cache or turn off caching.
Comment: Well it worked this time, so there must have been something else going on yesterday. Thanks!


Converting Annual GDP Growth Rate into Monthly GDP Growth Rate

Question: I am researching the effects of Euroarea fiscal stimulus on inflation expectations during the crisis. The data for fiscal stimulus is given as an annual percentage of GDP, e.g. 1.5% of Euro Area GDP in 2009.
Therefore, I am not sure if I could convert it to monthly data (by simply assuming 1.5% in every month for 2009) to show the effects of this stimulus on inflation expectations during this particular period.
P.S I need monthly data as my data for inflation expectations is monthly.
Can someone help with this please? Thanks.
Comment: What is the 1.5%? Is it the amount of fiscal stimulus (injected at one point or during a period)? Or is it the estimated effect of fiscal stimulus on GDP? If it is the latter, then I would be careful about assuming that the effect of fiscal stimulus was distributed evenly over the months. It's unlikely that by pure chance this was indeed the case, unless you have some other information telling you that.
Comment: Hi, thanks for your comment. The 1.5% is the total amount of stimulus injected in 2009 (during the 12 months)
Comment: So you would like to assume that the stimulus was injected in even amounts over the 12 months? I think this is a strong assumption. You had better try locate some monthly (or even finer) data for the execution of the stimulus instead of making this strong assumption. Also, inflation expectations could be mostly affected by the *announcement* of stimulus. If the announcement is credible, why should anyone react to its implementation if it fits with what was announced?
Comment: My idea was that if the stimulus for 2009 was 1.5% in 2009 in the Euroarea, I would find the month that it was announced (eg. June) and use this value of fiscal stimulus as a proxy. The problem lies in the fact that since I am analysing the Euroarea as a whole, and fiscal stimulus is implemented with differing amounts between each member state, I would need a total figure for the Euroarea (as my data for inflation expectations correspond to the Euroarea as a whole)
Comment: I don't quite understand... If you have stimulus for Euro area as a whole and inflation expectation for Euro area as a whole, what is the problem? The two seem to match each other alright. Also, you could benefit from updated the original post with all the relevant details you revealed in the comments. Then it would be easier for others to follow and contribute.
Comment: The data for inflation expectations is monthly data and the data for fiscal stimulus is annual, and so I would need to convert the Annual into monthly. This is the case since my period of analysis is short (2008-2013) and therefore I need a large enough dataset. Having said this my model includes another variable (changes in the ECB balance sheet) of which I have monthly data available
Comment: If you stick to the idea that inflation expectations depend on the implementation of stimulus and not only on its announcement, you would need actual data on implementation. Just assuming that the implementation intensity was flat over the whole implementation period is a bit much to assume, IMHO. Sometimes if you do not have the data, you cannot answer the question. If you try to assume too much to make your task simpler, you may trick yourself and get unreliable results. So my advice would be to get more data or at least make sure that your assumptions are close to reality.
Comment: Thanks for your valuable advice on my query. Do you do any consultancy for graduate students (as I am currently writing my thesis)? or would it be possible to contact you outside of this forum?
Comment: You are welcome! Currently I do not do any consultancy, sorry about that. One advice I could share is: try to make as clear and detailed a plan as you can. Go though it with your supervisor. Catch the problems before they have caused the damage. Once you have a sound idea of what you are doing and how you are going to do it, just do it. And keep posting questions here if they are fit for Cross Validated. By the way, any user should be notified if you write @username (e.g. @RichardHardy) somewhere on Cross Validated.
Answer: I don't think you can do this. See the following counter example. Assume the GDP at the beginning of 2009 was $100$. If it grew 1.5% every month, it would have been equal to $100\cdot1.015^{12} = 119.56$ at the end of 2009. However, since it grew 1.5% over the whole year the actual value at the end of 2009 was $101.5$. In order to get the correct average monthly compounding growth rate, you need a different approach.
Let $r$ be the average monthly compounding growth rate, $GDP_B$ the GDP at the beginning of 2009 and $GDP_E$ the GDP at the end of 2009. Then, the following holds: $GDP_E =  GDP_B \cdot (1+r)^{12} $. So you need to rearrange this in order to get the correct $r$:
$GDP_E =  GDP_B \cdot (1+r)^{12} \\
GDP_E/GDP_B  =  (1+r)^{12} \\
r = (GDP_E/GDP_B)^{(1/12)} - 1$
This means you get $r = (101.5/100)^{(1/12)} - 1 = 0.00124148771$.


activity do android studio não abre com botão click

Question: Meu problema é o seguinte. meu aplicativo possui uma tela de boas-vindas onde o usuário ckick o botão "continuar" e vai para a próxima tela. O próximo contém um menu com vários botões. meu problema é que não consigo abrir outra activity na segunda tela (na primeira tela que abre normal) mais ou menos este esquema abaixo (| activity1> botão continua | >> | activity2> botão continue2 |> não responde |tela3>> nao abre) para elogie e teste o apk em um galaxy grand duos 4.2.2
código abaixo
 tela do código 1 (bem-vindo).
public class Main2Activity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main2);
Button button7 = (Button) findViewById(R.id.button7);

button7.setOnClickListener(new View.OnClickListener() {
    @Override
    public void onClick(View view) {
        setContentView(R.layout.activity_main4);
    }
});}}

codigo tela 2
public class Main4Activity extends AppCompatActivity {
private  Button prova;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main4);

prova = (Button) findViewById(R.id.button5);

    prova.setOnClickListener(new View.OnClickListener() {
    @Override
    public void onClick(View view) {
        Intent intent = new Intent( Main4Activity.this,
    Main3Activity.class);
        startActivity(intent);
    }
});

}}

tela 2 codigo xml butao
            <Button
            android:id="@+id/button5"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_alignParentLeft="true"
            android:layout_alignParentStart="true"
            android:layout_below="@+id/button4"
            android:layout_marginTop="11dp"
            android:text="tela 2"/>

Answer: Olá,
O problema do seu App está no método onClick da primeira Activity, quando você executa o método setContentView(R.layout.activity_main4); você está apenas carregando o layout da tela, e não passando o controle do processamento para a próxima activity, então o método onClick do prova.setOnClickListener não é executado. Para corrigir o erro, crie uma Intent para chamar a Main4Activity. Substitua o trecho:
setContentView(R.layout.activity_main4);

por:
Intent intentProva = new Intent( Main2Activity.this,
Main4Activity.class);
    startActivity(intentProva);

Comment: muito bom, funcionou perfeitamente. obrigado!!!


Is there a "pattern" or a group that defines *rc files in *nix environments?

Question: I'm starting to use command line a little more, and I see there are a lot of ways to configure some config files in my $HOME. This is good, since you can customize it the way you really like.
Unfortunately, for begginners, having too many options is a little confusing. For example, I created .bash_alias for some alias I'm using. I didn't even know this option existed, I'm used to simply edit .bashrc.
Do exist a pattern, a "good practice", envisioning flexibility and modularity in terms of rc files structure? Do exist a standardization group for this, or every body just creates it's own configuration setup?
Answer: the configuration files are all dependent upon the software that uses them. in most cases, the file is named .<programname>rc in some cases it's a config file in a 'hidden' . directory, i.e. ~/.fluxbox/init
there is nothing wrong with putting your aliases in the .bashrc file, .bash_alias is another shell script called from within .bashrc, some people just like to segregate their configurations while others, like me, prefer putting all our related configurations in the same file, for easy management.
in my .bashrc there is:
#if [ -f ~/.bash_aliases ]; then
#    . ~/.bash_aliases
#fi

which is what i presume is in yours, only not commented out, meaning it checks that .bash_alias is a file, and then 'sources' it into the .bashrc file (that's what . ~/.bash_alias means, . in this case is a shortcut for source)


IDE integration vs running standalone Tomcat

Question: I've been always using the IDE Tomcat integration, where you just run a local Tomcat server through IDE (Intellij IDEA or Eclipse) to run your Java app. But now, some colleagues are claiming, that running a standalone Tomcat, or even Tomcat in a Docker container is actually better, because the configuration is not tied to your IDE.
That left me wondering, what are really the summed up advantages and disadvantages of either approach? Or is it basically the same thing?
Comment: Are you intending to put this application out into production somewhere? Presumably not running in your IDE?
Comment: Yes I am. The app will build after I push my commits to a Git repo.
Answer: Pros:

Developer see all required stuff in one single UI: logs, process status, etc
IDE can support Hot Swap on compile
IDE can automatically download and run tomcat for you. So you don't have to do this manually.

Cons:

IDE can implicitly add some configuration or java-agents. It can make running process less understandable for developer.

IMHO:
Using IDE for running Tomcat (or any other server) is good if you understand what exactly the IDE does for you and how to run it without IDE. You should clearly understand why you run the Tomcat in IDE.
Comment: Yes, that's exactly why I asked. I want to understand the advantages clearly. Thank you, I appreciate it.


Cut long string to paragraphs containing full sentences

Question: I have a task to translate very long text (more than 50k symbols) with online translate api (google, yandex, etc). All of them have limitation for request length. So, I want to cut my text into list of string with length less than those limitations but also save sentences uncut.
For example, if I want to process this text with limitation of 300 symbols:

The Stanford NLP Group makes some of our Natural Language Processing software available to everyone! We provide statistical NLP, deep learning NLP, and rule-based NLP tools for major computational linguistics problems, which can be incorporated into applications with human language technology needs.These packages are widely used in industry, academia, and government. This code is actively being developed, and we try to answer questions and fix bugs on a best-effort basis. All our supported software distributions are written in Java. Current versions of our software from October 2014 forward require Java 8+. (Versions from March 2013 to September 2014 required Java 1.6+; versions from 2005 to Feb 2013 required Java 1.5+. The Stanford Parser was first written in Java 1.1.) Distribution packages include components for command-line invocation, jar files, a Java API, and source code. You can also find us on GitHub and Maven. A number of helpful people have extended our work, with bindings or translations for other languages. As a result, much of this software can also easily be used from Python (or Jython), Ruby, Perl, Javascript, F#, and other .NET and JVM languages.

I should get that output:
['The Stanford NLP Group makes some of our Natural Language Processing software available to everyone! We provide statistical NLP, deep learning NLP, and rule-based NLP tools for major computational linguistics problems, which can be incorporated into applications with human language technology needs.',
'These packages are widely used in industry, academia, and government. This code is actively being developed, and we try to answer questions and fix bugs on a best-effort basis. All our supported software distributions are written in Java.',
'Current versions of our software from October 2014 forward require Java 8+. (Versions from March 2013 to September 2014 required Java 1.6+; versions from 2005 to Feb 2013 required Java 1.5+. The Stanford Parser was first written in Java 1.1.)',
'Distribution packages include components for command-line invocation, jar files, a Java API, and source code. You can also find us on GitHub and Maven. A number of helpful people have extended our work, with bindings or translations for other languages.',
'As a result, much of this software can also easily be used from Python (or Jython), Ruby, Perl, Javascript, F#, and other .NET and JVM languages.']

What's most pythonic way to do it? Are there any regexps to achieve that?
Answer: regex is not the right tool to parse sentences out of paragraphs. you should look at nltk
import nltk

# this line only needs to be run once per environment:
nltk.download('punkt')

text = """The Stanford NLP Group makes some of our Natural Language Processing software available to everyone! We provide statistical NLP, deep learning NLP, and rule-based NLP tools for major computational linguistics problems, which can be incorporated into applications with human language technology needs.These packages are widely used in industry, academia, and government. This code is actively being developed, and we try to answer questions and fix bugs on a best-effort basis. All our supported software distributions are written in Java. Current versions of our software from October 2014 forward require Java 8+. (Versions from March 2013 to September 2014 required Java 1.6+; versions from 2005 to Feb 2013 required Java 1.5+. The Stanford Parser was first written in Java 1.1.) Distribution packages include components for command-line invocation, jar files, a Java API, and source code. You can also find us on GitHub and Maven. A number of helpful people have extended our work, with bindings or translations for other languages. As a result, much of this software can also easily be used from Python (or Jython), Ruby, Perl, Javascript, F#, and other .NET and JVM languages."""

sents = nltk.sent_tokenize(text)

sents
# outputs:
['The Stanford NLP Group makes some of our Natural Language Processing software available to everyone!',
 'We provide statistical NLP, deep learning NLP, and rule-based NLP tools for major computational linguistics problems, which can be incorporated into applications with human language technology needs.These packages are widely used in industry, academia, and government.',
 'This code is actively being developed, and we try to answer questions and fix bugs on a best-effort basis.',
 'All our supported software distributions are written in Java.',
 'Current versions of our software from October 2014 forward require Java 8+.',
 '(Versions from March 2013 to September 2014 required Java 1.6+; versions from 2005 to Feb 2013 required Java 1.5+.',
 'The Stanford Parser was first written in Java 1.1.)',
 'Distribution packages include components for command-line invocation, jar files, a Java API, and source code.',
 'You can also find us on GitHub and Maven.',
 'A number of helpful people have extended our work, with bindings or translations for other languages.',
 'As a result, much of this software can also easily be used from Python (or Jython), Ruby, Perl, Javascript, F#, and other .NET and JVM languages.']

One way to aggregate sentences based on cumulative length is to use a generator function:
Here, the function g will yield a joined string if the string's length exceeds 300 characters or the end of the iterable is reached. This function assumes that no single sentence exceeds the 300 character limit.
def g(sents):
    idx = 0
    text_length = 0
    for i, s in enumerate(sents):
        if text_length + len(s) > 300:
            yield ' '.join(sents[idx:i])
            text_length = len(s)
            idx = i
        else:
            text_length += len(s)
    yield ' '.join(sents[idx:])

The sentence aggregator can be called like this:
for s in g(sents):
    print(s)
outputs:
The Stanford NLP Group makes some of our Natural Language Processing software available to everyone!
We provide statistical NLP, deep learning NLP, and rule-based NLP tools for major computational linguistics problems, which can be incorporated into applications with human language technology needs.These packages are widely used in industry, academia, and government.
This code is actively being developed, and we try to answer questions and fix bugs on a best-effort basis. All our supported software distributions are written in Java. Current versions of our software from October 2014 forward require Java 8+.
(Versions from March 2013 to September 2014 required Java 1.6+; versions from 2005 to Feb 2013 required Java 1.5+. The Stanford Parser was first written in Java 1.1.) Distribution packages include components for command-line invocation, jar files, a Java API, and source code.
You can also find us on GitHub and Maven. A number of helpful people have extended our work, with bindings or translations for other languages. As a result, much of this software can also easily be used from Python (or Jython), Ruby, Perl, Javascript, F#, and other .NET and JVM languages.

Examining the length of each text segment shows that all the segments have fewer than 300 characters:
[len(s) for s in g(sents)]
#outputs:
[100, 268, 244, 276, 289]

Comment: Thanks for your answer!
But what's the fastest way to join sentences until string has longest length and less than 300 in the same time? Actually, sentences can be mixed, it is not a big problem


How do I build a HTML table from Glazed List?

Question: Lat week I downloaded the Glazed List library into eclipse. I have been looking through the tutorials and it seems that everything is designed to run jTable or SWT. I am need a backing list(Map, table, whatever) for simple HTML tables that can be sortable. I have been doing this by rolling my own classes to create HTML tables from either Lists or Maps(Very Large Lists and Maps). No scripting allowed.
Is Glazed List overkill for what I am wanting to do? If there is a way, could someone point me in the right direction, perhaps a example or a tutorial.
Answer: I think it is not exactly the right tool for the job.  GlazedLists was created to support mostly Swing or SWT based UIs.  You can get it to work well as a backing model for the HTML table on the server side, but you would have to create the rendering code yourself.
In this URL you can see that the documentation mentions that it can be used with swing or SWT out of the box, but no HTML mentioned:
http://sites.google.com/site/glazedlists/propaganda/features#TOC-Swing-or-SWT
All said, however, it does make a good backing model.  Creating the rendering code might not be so hard.
Answer: We had a volunteer for an official GWT port, but it's not available yet. In an unrelated effort, there's an EventList in the gwt-stuff project, but I haven't investigated it.


Showing that these two quotient spaces are not homeomorphic

Question: Let, $P$ be the quotient space obtainted from $S^{2}$ by identifying two distinct points and $Q$ be the quotient space obtained by identifying three mutually distinct points in $S^{2}$. Show that these two spaces are not homeomorphic.
Any suggestions? I'm very confused by the quotient topology section in Munkres and I can't even visualize what these spaces are supposed to "look" like.
Comment: Just imagine two or three protrusions on the surface of the sphere with those points at their tips, and then glue the tips. These spaces have different homotopy groups, the number of independent non-contractible loops is different, in particular.
Answer: Sketch: There is a point $q\in Q$, namely the point to which the three points identify, such that there is a (path-)connected open neighbourhood $U$ of $q$ such that $U\setminus \{q\}$ has three (path-)connected components, whereas for all (path-)connected open sets $V\subseteq P$ and for all $p\in P$, $V\setminus\{p\}$ has at most two (path-)connected components.
For the part about $P$, one must mak the case of whether or not $V$ contains the image $c$ of the two points and $p=c$.
If you want a visual embedding in $\Bbb R^3$, grab the two/three points you want to identify and pull the surface of $S^2$ so that those points become the tip of an equal number of little horns. Then stretch said horns and have their tips meet. Depending on the initial number of points, you end up with $P$, $Q$ or possibily something else.
There is of course the inverse construction, where you start with two or three cone-hats having the tip in common and so that no one lies in the interior of the other. Let their bottoms rest on a $S^2$ and join them by attaching the portion of sphere that is outside of all the cones.
Comment: How do we know that $V\{q}$has at most two path-connected components and that $ U\{q} $ has at most three path-connected components?
Answer: Think of the quotient topology like collapsing/gluing subspaces. So in this problem you can visualize P like a balloon which you have pinched from opposite sides until they meet at one point in the middle. It's homeomorphic to the surface in $\mathbb{R}^3$ defined by
$$z^2 = (x^2 + y^2)(1-x^2-y^2).$$
Q is the same idea, except you glue three points together.
As for showing that they're not homeomorphic, you just need to find any topological property that is different between them. As in Gae's answer, I would look at small connected neighborhoods of the point of gluing $q$, and then delete the point $q$ from them. For P the resulting neighborhoods will have two connected components, for Q they will have three.


Script Batch para Selecionar Arquivos por Data

Question: Gostaria de criar um script Batch que faça uma varredura dentro de uma pasta e suas sub-pastas, encontrando os aquivos XML e colocando em uma pasta temporária.
Para que depois, eu possa compactar usando o 7-Zip.
Abaixo segue script usando o WinRAR, mas queria fazer sem usar um programa e sim comandos.

<code>@echo off
:: a adicionar ficheiros para um arquivo
::-ep excluir caminho nos nomes
::r reparar arquivo danificado
::-ta<date> processar arquivos informados apos a data fornecida
::-tb<date> processar arquivos informados anterior a data fornecida
echo Informe os dados corretamente.
echo #######################
set LOCAL_XML=C:\Fashion 2.0\nfce\arquivos\assinado\*.XML
set LOCAL_XML_2=C:\Fashion 2.0\nfe\arquivos\assinado\*.XML
SET LOCAL_BACKUP="D:\Documentos\Desktop\Shopsync"
SET ZIPADOR=C:\Program Files\WinRAR\WINRAR.EXE
del *.zip
echo Digite o Ano:
SET /p ANO=
echo Digite o Mes:
SET /p MES=
echo Digite a Data Inicial:
SET /p DIA_INICIAL=
echo Digite a Data Final:
SET /p DIA_FINAL=
echo Aguarde gerando arquivo compactado...

CD
"%ZIPADOR%" a -ep -r -ta%ANO%%MES%%DIA_INICIAL% -tb%ANO%%MES%%DIA_FINAL%235959 %LOCAL_BACKUP%\vendas%ANO%%MES%%DIA_INICIAL%" a "%ANO%%MES%%DIA_FINAL%.zip "%LOCAL_XML%"
"%ZIPADOR%" a -ep -r -ta%ANO%%MES%%DIA_INICIAL% -tb%ANO%%MES%%DIA_FINAL%235959 %LOCAL_BACKUP%\vendas%ANO%%MES%%DIA_INICIAL%" a "%ANO%%MES%%DIA_FINAL%.zip "%LOCAL_XML_2%"

</code>
Answer:

<code>@echo off & setlocal enableextensions enabledelayedexpansion & title <nul

mode 79,10 & color 0a & title Q38135.cmd

set "_bck=D:\Documentos\Desktop\Shopsync"
set "_Zip=C:\Program Files\WinRAR\Rar.exe"

set "_xml=C:\Fashion 2.0\nfce\arquivos\assinado"
set "_xml="!_xml!","C:\Fashion 2.0\nfe\arquivos\assinado""
set "_ptp="%__APPDIR__%\pathping.exe" 127.1 -n -q 1 -p 40""

call :^) && for /l %%l in (1 2 70)do cls & echo=!_lf! && if not "%%l" == "70" (
  echo/ & echo= !_ul:~-%%l! & echo= !_ban:~-%%l! & echo= !_ul:~-%%l! & echo/
  echo= !_lf! &!_ptp! 2>nul >nul) else echo/ !_ul! & echo= !_ban! & echo=!_ul!

cd /d "!_bck!" & for %%s in (ini,fim)do set/p "_%%~s=!_msn!" && call :^[ "!_%%~s!" "%%~s"
set "_tag=-ta!_ini:/=!000000 -tb!_fim:/=!235959" & set "_bck=!_bck!\Vendas_!_fim:/=-!_Final.Rar" && (
for %%x in (!_xml!)do title .: Backup NFCe/NFe ^| "%%~x" Gerando Arquivo "!_fim:/=!_Final.Rar" :.&& (
  "!_zip!" a -ep -r !_tag! "!_bck!" "%%~x\*.xml" && echo/ Backup efetuado^!!)) & endlocal & goto :^V

:^)
:: seta variaveis para uso na interface de comando ::
set "_msn= Informe data inicial com o formato AAAA/MM/DD: " && set _lf=^

<nul 2>nul & cmd /v/c set "_lf=!_lf!^!_lf!"
>nul set "_ul=------------------------------------------------------------------ "
>nul set _ban=^
    ----- * B A C K - U P :  N F C e  ^&  N F e / X M L * ----- && exit /b

:^[
set "_msn=!_msn:data inicial=a data final!" & set "_str=%~1"
for /f %%s in ('cmd /u/c set /p "=%_str: =%"^<nul^|find /v /c ""')do set "_cnt=%%s"
for /f %%s in ('cmd /u/c set /p "=%_str: =%"^<nul^|find /c "/"')do set "_bar=%%s"
set /a "_num=!_cnt!-!_bar!" & for %%i in (cnt-10,bar-2,num-8)do for /f "tokens=1,2delims=-" %%A in ('
echo=%%i')do if not "!_%%A!"=="%%B" (for /l %%L in (1 1 4)do if "%%L"=="4" (echo/ ERRO: Data Informada %~1:
     endlocal & timeout -1 2>nul & call "%~f0" & exit /b) else set "_msn=!_msn:data inicial=a data final!"
     )
set "_str=" & exit /b

:^V
</code>


A square implies AA^{T} SPD

Question: If A is square and real valued, does is follow then that $AA^{T}$ is symmetric positive definite?
I really don't see how to work out. Does someone have a hint?
Comment: SPD is semi-positive definite?
Comment: Symmetric positive definite :)
Comment: Ahh.  So the answer is "almost", because if $A$ is not invertible, you will have zero eigenvalues (so it is positive semi-definite).  But as a first step, do you know why it is symmetric?
Answer: 1) $AA^T$ is symmetric:
$$(AA^T)^T=(A^T)^TA^T=AA^T$$
2) $AA^T$ is positive semidefinite:
$$\langle AA^Tx,x\rangle=\langle Ax,Ax \rangle = \|Ax\|^2\geq 0$$
Answer: There is never any shame in experimenting with "random" matrices. Try to find a nice matrix $A$ which is obviously singular. What can you say about the singularity of $AA^T$?
Comment: This is a nice comment, but I wouldn't consider it a proper answer to the question
Comment: I would like to understand your position better. Would you elaborate on this point? The OP asked *not* for the solution, but for a hint. I am quite new to this forum, but *not* to teaching. My hint would allow the OP to do the "hard" part himself, and discover that $AA^T$ can be indefinite.
Comment: I misread the question originally; your answer is fine. I thought he wanted to prove the matrix was psd.
Comment: Thanks. All is well. These things happen :)
Answer: Hint: Let $\langle x,y \rangle = x^T y$ be the standard inner product on $\mathbb R^n$.  Now, let $x$ be an eigenvector of $AA^T$, and compute $\langle AA^Tx,x \rangle$ two different ways.

A square implies AA^{T} SPD


lm() coefficients -> vector with commas

Question: Question:
I want to put the coefficients from a call to lm() into a vector with commas such as
vec=c(325.4361167,0.0675257,2.5519813,3.8001944,-22.9494678,2.4174843 )
How to do?
My Code
fit <- lm(y~x1+x2+x3+x4+x5)
fit
fit$coefficients
class(fit$coefficients)
vec <- c(fit$coefficients)
vec
coeffs <- coefficients(fit) does the same.

Output:
> fit
Call:
lm(formula = y ~ x1 + x2 + x3 + x4 + x5)

Coefficients:
(Intercept)           x1           x2           x3           x4           x5
  325.43612      0.06753      2.55198      3.80019    -22.94947      2.41748

> fit$coefficients
(Intercept)          x1          x2          x3          x4          x5
325.4361167   0.0675257   2.5519813   3.8001944 -22.9494678   2.4174843

> class(fit$coefficients)
[1] "numeric"

> vec <- c(fit$coefficients)
> vec
(Intercept)          x1          x2          x3          x4          x5
325.4361167   0.0675257   2.5519813   3.8001944 -22.9494678   2.4174843

> coeffs <- coefficients(fit)
> coeffs
(Intercept)          x1          x2          x3          x4          x5
325.4361167   0.0675257   2.5519813   3.8001944 -22.9494678   2.4174843
>

My Data
   id     y     x1    x2    x3    x4    x5
1   1 271.8 783.35 33.53 40.55 16.66 13.20
2   2 264.0 748.45 36.50 36.19 16.46 14.11
3   3 238.8 684.45 34.66 37.31 17.66 15.68
4   4 230.7 827.80 33.13 32.52 17.50 10.53
5   5 251.6 860.45 35.75 33.71 16.40 11.00
6   6 257.9 875.15 34.46 34.14 16.28 11.31
7   7 263.9 909.45 34.60 34.85 16.06 11.96
8   8 266.5 905.55 35.38 35.89 15.93 12.58
9   9 229.1 756.00 35.85 33.53 16.60 10.66
10 10 239.3 769.35 35.68 33.79 16.41 10.85

Thank you.
MM
Answer: Your vec object is already vector "with commas" such as used when making one with c(). It is  a named numeric vector, so it looks a little different. If you want to get rid of the names, you can do unname(vec). If you want to make one string with them separated by commas, you can do paste(vec, collapse = ", ").
Comment: I needed to prepare for a run of paretoChart after running lm.beta to get standardized coefficients. I store the results in fit_std.  Then stdBetaCoeff <- abs(coefficients(fit_std))
followed by pareto.chart(stdBetaCoeff). I still need to work on your post, however. I need to take the mystery out of vectors. Thanks. MM

lm() coefficients -> vector with commas


How to count this measure?

Question: I am learning a piece and am new to sheet music. I am trying to count the beats, and need to some help in counting.
It's in the time signature 4/4.
For the second bar, how should I count it out?
My interpretation:
<code> (0 3) 1 & beat
 0--    ?
 2---   ?
 (3 0) 1  & beat
</code>
Answer: I assume this is plucked guitar strings without any active muting.
Hence the notes will continue to ring out, but won't really be "held" in the same sense the other instrument might do.
I'm not sure why it's been written the way shown (as two seperate voice), but if you rewrite it as a single voice (removing the unnecessary tied notes etc.), it is much easier to see the rhythm:

(PS I don't understand your notation at all.)
Answer:
(0 3)   1 &
(0 2)   2 & 3 &
(3 0)   4 &

How to count this measure?


Is an application-wide Observer a valid solution?

Question: I'm using the Reactive framework in C# and I am curious if using an application wide observer (Singleton Message Bus) is a worthy cause? In a quarantined section of the application it works like a charm but I am curious if anyone has any wisdom that screams, "NO! WTF ARE YOU THINKING!"
Technical input as well as theoretical Pattern knowledge is more than welcome!
Comment: I never heard about "message bus". Please somebody provide some links where I can get some information on this topic.
Comment: Same kind of question as "should I make my class methods protected or private?"  Same answer.
Comment: Since I'm quite excited about Rx, I would be very interested in a short code example. Could you show how you've set up that "global" obsever, and another brief example how you're using it?
Answer: I used an approach like this in one of my old C/C++ applications.  It has the advantage that you can decouple modules, but in my experience it quickly leads to lots of problems in bigger applications:

You lose control of what's really happening in your application.  Since every module can listen to the message bus, also every module can influence every other module of the application.
If the message bus is the only way to notify observers, sending out notifications can have unpredictable performance effects.
To solve some of the performance problems, you can try to initiate buffering messages (messages like "I will do a lot of things, so don't react immediately" and "OK, I'm done now, you may process everything I told you") but this may lead to unpredictable effects as well.

My conclusion is that a global message bus is a nice idea for small applications, but not for big ones.  By using one global message bus to decouple all your modules, you effectively achieve the opposite, since everyone is now linked to everyone else, making it harder in the long term to untangle your application again.
I would suggest to make every module as independent as possible, and to use specialized observers (see observer pattern of the Gang Of Four).
Answer: This pattern is widely used to decrease tie-up between app components. I've used it in a few of my projects and it's really very cosy and useful.
I'm talking about pattern in general, I don't know how is it implemented in Reactive framework.


Drop unused parameters from model?

Question: I have trained a model using caret's train function in R (LASSO logistic regression with glmnet, repeatedcv). The goal is both feature selection and getting the model. With the preferred lambda, LASSO penalized many variables to zero, as expected. I then tried to use the model to predict outcomes with the predict function, that data only includes variables that were not penalized to 0 in the model training. Surprisingly, the predict function returns an error and expects all variables, including those that were non-predictive in feature selection.
How can I completely drop these variables from the model to use it for predictions? Am I missing an obvious point here?
Comment: Prediction is just a matrix multiplication with the coefficient vector (assuming you have a Gaussian model, otherwise you also need to apply the inverse link function). So, something like this should work for you: `coef <- coef(fit, s = preferred_lambda);
cbind(1, newx) %*% as.vector(coef[coef != 0])`
Comment: Why do you need to drop variables whose parameters are estimated as $0?$
Comment: @Roland Thanks! I feel like I am very close, but am not entirely sure how to implement this in my fit. The fit is from caret (class= 'train'). I can extract the coefs as expected, but am not sure how to subset the fit object using the final coef vector. The goal is to run predict(fit, newdata, type = "prob"). That function indeed already seems to automatically use the bestTune that is stored in the fit (so correctly chooses alpha and lambda), but still expects the irrelevant variables as input.
So far I've tried to subset fit$coefnames , but that doesn't do the trick.
Comment: @Dave Because they are otherwise expected as input using predict(), even though their values are not considered in the prediction.
Answer: Those features are in the model, just with their coefficients set to zero. Consequently, the software is being quite reasonable in expecting those variables in the data frame for which you want to make predictions.
I see three options.

Supply those variables, knowing the values will not affect the predictions (since the coefficients are zero).

Make up values for those variables (such as all zero), since their values do not affect the predictions. This could be useful if you need to do complex data wrangling to access those values, resulting in either slow performance or irritation to the programmer. This could be useful, too, if you stop collecting data on the variables that do not survive the LASSO estimation.

Do the vector multiplication on your own, outside of the usual prediction method. This will involve matrix multiplication of the data frame with the "surviving" features times the vector of nonzero LASSO-estimated regression coefficients. You're always allowed to say that the model is something like $\hat y_i=\hat\beta_0+0x_{i1}+\hat\beta_2x_{2i}=\hat\beta_0+\hat\beta_2x_{2i}$.

Drop unused parameters from model?


dificuldade pra listar os dados no datatable do angular 4

Question: Como título diz, não consigo carregar os registros do banco no dataTable do PrimeNG.
Não aparece mensagens de erro no console do VisualCode, não aparece mensagens de erro no console do navegador de internet, não aparece notificações de erro no próprio código.
Eu acho que o problema deva ser no HTML, preciso de ajuda para saber como resolver isso, esse aqui é meu código.
Código do serviço;
import { Noticia } from './../core/model';

import { Http, Headers } from '@angular/http';
import { Injectable } from '@angular/core';

import { Observable } from 'rxjs/Observable';

import 'rxjs/add/operator/map';

@Injectable()
export class NoticiaService {

  noticiasUrl = 'http://localhost:8080/noticias';

  constructor(private http: Http) { }

  pesquisar(): Observable <Noticia[]> {
    return this.http.get(`${this.noticiasUrl}`)
      .map(response => response.json().content);

  }

}

Código do componente;
noticias = [];

  constructor(private noticiaService: NoticiaService) { }

  ngOnInit() {
     this.pesquisa();
  }

  pesquisa() {
      this.noticiaService.pesquisar()
      .subscribe(noticias => this.noticias = this.noticias);
  }

Código HTML;

      Descrição
      <input pInputText type="text">

      Vencimento
      <input pInputText type="text" style="width: 95px">

      até
      <input pInputText type="text" style="width: 95px">

      <button pButton type="submit" label="Pesquisar"></button>

        <ng-template let-lanc="rowData" pTemplate="body">
          {{ lanc.dataNoticia | date:'dd/MM/yyyy' }}
        </ng-template>

              <ng-template let-lanc="rowData" pTemplate="body">
                <button pButton icon="fa-angle-double-right"
                pTooltip="Visualize" tooltipPosition="top"
                ></button>
              </ng-template>

Comment: Faz um teste coloca um *ngIf="noticias" no div em volta da p-dataTable
Comment: Como eu colocaria isso no Datatable?
Answer:   ngOnInit() {
     this.pesquisa();
  }

//O erro estava que tinha um this extra aqui
  pesquisa() {
      this.noticiaService.pesquisar()
      .subscribe(noticias => this.noticias = noticias);
  }

Comment: você está dizendo que o erro está nesse trecho de código, mas não consigo ver diferença com o meu código.
Comment: O seu esta .subscribe(noticias => this.noticias = this.noticias);
Comment: O segundo nao devia ter o this
Comment: hahaha, valeu, muito obrigado


How to interpret a logistic regression result with continuous variables?

Question: I am conducting a regression analysis.
I have a first problem and that is that the database has only an n of 41 (n=29 for one group and n=12 for the second group).
But I have gone ahead with the logistic regression. For this I used the following code:
<code> model<-glm(grupo ~arrayil2+citometriail2+citometriail4+citomtriail5,
     data = BD,
     family = binomial(link="logit"))
</code>
The "group" variable is whether the patient is asthmatic or not and the variables arrayil2, cytometriail2, cytometriail4, cytomtriail5 are continuous values.
<code>TABLA<-logistic.display(model,crude.p.value = TRUE, decimal = 3);TABLA<-as.data.frame(TABLA)
</code>
This gives me the following result:

I don't quite understand the result, as I usually perform logistic regressions with a larger n and with categorical variables.
I would need help in interpreting these results and whether they are wrong or not.
Thanks in advance.
Comment: No, random forest, because it is nonparametric and puts no structure on the problem, does not benefit from an additivity assumption and requires 10x higher samples size than logistic regression.  See https://bmcmedresmethodol.biomedcentral.com/articles/10.1186/1471-2288-14-137 where estimates of 200 **events** per candidate feature are required for RF.
Comment: Frank Harrell is right that doing this analysis with only 41 observations is likely hopeless and that a random forest approach, no matter how well RF can perform in some situations, is unlikely to save you from your small sample size (fewer assumptions means a greater need for data to figure out what is happening). However, interpreting such a table, had you used (say) 41,000 observations, is a reasonable question. It might help to format the table so it's easier to read and doesn't cut off pieces of text.
Comment: That paper did not use a valid accuracy score and should be ignored.  RF like CART (recursive partitioning) needs incrediblly large sample sizes.   See again the reference I posted above.  In addition to other severe problems with RF in your context, your sample size is not 1/10th as large as what's needed to determine the tuning parameters needed for RF.  It is a grave mistake to think that RF can get by with smaller samples than LRM.  The exact opposite is the case.
Comment: What you think "works" in fact doesn't.  As expert Rob Tibshirani explained at a statistics meeting, RF is for "tall and thin" data which is not what most practitioners think.  RF needs a huge number of observations and not many candidate variables to have satisfactory performance.  Of course that is the exact situation where regression works quite well.  Most people who think that something "works" do not use correct accuracy scores in the assessment, and do not routinely derive smooth nonlinear calibration curves to assess absolute predictive performance.
Comment: The minimal sample size for estimating a single proportion is $n=96$.  That is equivalent to estimating only an intercept in a logistic model.   So this is pretty hopeless.  See https://hbiostat.org/rmsc/lrm.html .   By all means ignore all point estimates and look only at confidence intervals.
Comment: Thank you @FrankHarrell. I have conducted a random forest as an alternative to this analysis because it does not requiere a minimum sample size.
Comment: https://stats.stackexchange.com/search?q=interpret+logistic+regression
Comment: I do not understand @FrankHarrell I have seen many articles which explain that RF over the sample size problem. see https://www.sciencedirect.com/science/article/pii/S0165783620300515?casa_token=i28hz0GmV0UAAAAA:pgwG2pMS30ylFoTJbMBIeqzOJBDpTTAQ4b9gx1uB-OUjQkdXN9gQIJrjIOQ609cCJXTMrfLR0A
Comment: @FrankHarrell Typically the one restriction on random forest is that your number of features should be quite big - the first step of RF is to choose 1/3n or sqrt(n) features to construct a tree (depending on task, regression/classification). So if I have quite a lot of features, I can use RF even on small dataset - there is no algorithm that works really good on small datasets so I do not loose nothing.
Answer: As indicated in the comments, your particular model with this particular small data set is uninterpretable. The odds-ratio estimates and confidence intervals (as best as I can tell from the image of the table) seem to be enormous. I suspect that you have something close to perfect separation with only 12 cases in the minority class and 4 continuous predictor variables.
Otherwise, the interpretation of a coefficient for a continuous linearly modeled predictor in logistic regression is straightforward: it's the increase in log-odds of an event per unit change in that continuous predictor.


Display All Values in Local Option Set (picklist) Despite Records Per Page Limitation

Question: I have a local option set (picklist) that is populated from a "Query CRM Data" query. The query returns all users. Currently, the number of users is greater than the records per page (set to 50), so only the first 50 users are displayed in the option set. I cannot change the default number of records per page as this would cause a big performance hit in the system.
Is there a way for me to be able to display all records in an option set (picklist) where the number of records is greater than the records per page setting? I need to be able to select multiple users at once, so I think that rules out the Lookup.
Any thoughts? Much appreciated. Thanks.
Comment: I assume you are talking about prompt and response in dialogs, don't you? I might be missing something, but can you select more then one option in picklist?
Answer: You mention "Query CRM Data" so I take it you're creating a Dialog. Unfortunately the answer is no, you can't exceed the 50 limit of option sets on a dialog. You can only go beyond this limit when you have control over the query execution (such as in javascript or C#).
So in short, you'll have to use lookups. And also, as MarioZG mentions, you can only select 1 option in a option set/picklist anyway, so a picklist doesn't solve your other problem.
Comment: Ah for some reason I had thought you could select multiple in a picklist. I'm sure there's a way to do that with some javascript but seeing as it isn't part of my requirements, I think I can go with the lookup! So for that I just have to create a relationship to the User entity on the field I'd like to use, correct?
Comment: There's 2 ways to do it. Either create a relationship between the entities, or go to "Fields" on the target entity and add a new lookup field to point at the users entity. Both achieve the same thing


Sequence of exponential random variables

Question: Let $\mathcal{E}=\{E_n : n\geq 1\}$ be a sequence of independent exponential random variables with mean 1. How can I see the set $E=\{E_n(\omega) : n\geq 1\}$ dense in $[0,\infty)$? I imagine one can make an argument about the cdf being discontinuous if there's an open set that doesn't contain any $E_n(\omega)$, but I don't know if this is even the right direction.
Answer: Let $a <b$. Then $$P(E_n \notin (a,b) \,  \forall n \in \{1,2,..,N\})=\prod_{k=1}^{N} P(E_n \notin (a,b))$$ $$ =\prod_{k=1}^{N} (e^{-a}-e^{-b})=(e^{-a}-e^{-b})^{N} \to 0$$ as $N \to \infty$. Hence, $P(E_n \notin (a,b) \,  \forall n )=0$. Taking union over all rational values of $a$ and $b$ we see that there is one null set $E$ such that $\omega \notin E$ implies $(E_n(\omega))$ intersects every open interval in $\mathbb R$.


Commerce Pricing Rules Not Applying During Checkout

Question: I have a pricing rule that's defined essentially along the lines of the one described here, and it appears correctly when I add items to the cart. But as soon as I progress to the check out the prices all revert to their base price not the discounted price.
With the Rules debugging enabled all the rules appear to fire, but the calculation doesn't appear to be saved correctly. Since there aren't a lot of hits in Google for this (or at least for the various search terms I can think of) I presume we're doing something odd that's causing trouble, but I've slowly removed every complexity I can so I'm as close to the user guide example as I can all without success.
Answer: The problem was the Rules 2.8 regression resolved by Commerce 1.11.


Which statistical method to use for data with factor-based dependent variable

Question: I have a data set with many variables which are factors or discrete string values. For example students are allowed to choose any one of three courses offered. The choice of student may depend upon the price, timing, location, teacher etc.
Now linear regression as I understand is out of question here because it doesn't work with dependent variables having discrete string values.
Another choice available in statistics is logistics regression but as I understand it, its outcome is dichotomous(e.g., success/failure, yes/no, chosen/not chosen  or died/lived.)
If I apply logistic regression on my data will it help me find the answer that which factors effect the choice of students in choosing a course?  Or in another example what factors were effecting the choice of a person decided to sell a product by joint venture mechanism instead of distribution and by how much?
If there are any other statistical methods available for handling these types of questions, please let me know.  Thanks.
Answer: If I understand you correctly, the method you are looking for is multinomial (polytomous) logistic regression (mlogit in Stata, for R see http://www.ats.ucla.edu/stat/r/dae/mlogit.htm). In most packages the outcome category that is most frequent becomes the reference category and you get two sets of regression results for the other two categories as compared to the reference category outcome. You can always change the reference outcome if preferred. The interpretation of the coefficients is the same as logistic regression - log odds, and again in comparison to the reference outcome. Another possibility is to use conditional logistic regression.


How Roman Picisan Constructed

Question: This is one of the "sacred" song by one of the legendary band in Indonesia. The song is called Roman Picisan. I want to know more how this song constructed especially in the verse section (what mode or scale this song in). I have limited knowledge in music theory but by using my ear here's what I got
Verse (0:52 - 1:20)
|Am . . .|E . . .|Am . . .|E . . .|
|Dsus2 . Bb/D .|C . G .|Dsus2 . Bb/D .|C . G .|
|Gmaj7/D . . .|Dm . Am .|E . Am .|
Reff (1:20 - 1:37)
|A . . .|C#m . . .|Em . . .|Dm . . .|
|A . . .|C#m . . .|Em . . .|Dm . . .|
I got two questions, first is in what scale or maybe the mode is the verse in because it's a weird chord progression for me. Second, how the modulation works from verse to reff because the verse is ended with Am chord but it's suddenly jump to A chord and it's still sounds good (for my ear).

Link for the song: Roman Picisan (Song starts at 0:50)
Answer: A lot of things are going on in the song!
The verse is in A minor, it starts with a simple Am/E vamp.
Then it plays Dm/ Bb/D / C / G. The only "strange" chord is Bb/D, Bb in first inversion that is. It is the bII chord of the A minor scale and is called the neapolitan chord.
It creates a very beautiful sound, because it encloses the A note between the Bb (one half step after it) and the G# of the previous E chord (one half step below A). This chord does not strictly belong to the A minor scale because Bb is not diatonic to it, but we just explained why "it works".
C and G are just diatonic to the key, nothing strange here.

In the chorus we modulate to A major. This is common in a lot of songs and pieces (Why my guitar gently weeps by The Beatles, first that comes to my mind, or Time in a bottle by Jim Croce). It gives an uplifting feeling to the song, because it changes the mood by staying in the same range at the same time.
The modulation works by just doing it ^^. Some pieces in minor actually end on the corresponding major chord to give a relieving feeling - this device is called tierce de picardie, but does not apply in this case because it is not the final chord of a section, but the first of a new one.
Actually the mode is not strictly A major, but A mixolydian because of the Em chord - the fifth chord of the mixolydian mode is minor, as opposed to the major/ionian where it is a dominant one (V7).
This twists things a bit by making them less obvious. Then we have a iv chord, D minor, that should be major in both ionian an mixolydian. You can see it as a borrowed chord from the parallel minor we were in before (A minor), so we can transition better to the previous key.

How Roman Picisan Constructed


XNA spriteBatch.Draw - flickering sprites

Question: I'm writing sprite animation in XNA. I use spriteBatch.Draw method to do this:
spriteBatch.Draw(waterTexture, waterPosition, rectWater, Color.White * 1.0f, 0f, Vector2.Zero, 1.0f, SpriteEffects.None, 1.0f);
// 'rectWater' is rect used to cut sprite image from sprite texture

The problem is that it almowst works, but near end of animation it blinks once and continue animation. What could it be?
Comment: Sounds like your animation for this sprite has 1 too many frames. We're going to need some more code, to make sure.
Answer: Ok, I figured out what was wrong.
The problem was, that I had wrong alghoritm to change frames, and it was sometimes skipping to blank frame. Look at the code:
Rectangle rectWater = new Rectangle(((currentFrame % numerOfWaterSpriteFrames) % horizontalNumerOfWaterSpriteFrames) * (int)sizeOfWaterFrame.X, ((aktualnaFramka % numerOfWaterSpriteFrames) / horizontalNumerOfWaterSpriteFrames) * (int)sizeOfWaterFrame.Y, (int)sizeOfWaterFrame.X, (int)sizeOfWaterFrame.Y);
//The correct code

I wasn't moduling the currentFrame by numerOfWaterSpriteFrames in first and second Rectangle constructor parameter. Just like this:
Rectangle rectWater = new Rectangle((currentFrame % horizontalNumerOfWaterSpriteFrames) * (int)sizeOfWaterFrame.X, (aktualnaFramka / horizontalNumerOfWaterSpriteFrames) * (int)sizeOfWaterFrame.Y, (int)sizeOfWaterFrame.X, (int)sizeOfWaterFrame.Y);
//The wrong code

It's ok now.
Answer: I can't really help much without seeing the code that's animating the sprite, but a blink at the same point in the animation every time suggests a dud frame to me. What's probably happening is you're drawing a blank frame at the end. A likely cause of this is a straightforward off-by-one error; if you're using a loop to iterate over the frames of your animation, then your index might be out by one (using >= instead of >, for example) which means you're drawing an extra frame that shouldn't be in there. The fact that you're getting a blank frame instead of a crash suggests that the extra frame falls within the spritesheet, either by the structure of your animation algorithm or by luck.
I'd need to see the animation code to be sure what's happening, though.


How to configure or customize REALM Metadata endpoints in Keycloak for SAML2.0

Question: Context:
I have a keycloak inside a docker, I understand that there is a "proxy reverse" doing something like transforming this url for example: "http://example.com" into "http://126.96.36.199:8082" (this is the actual place where the Keycloak is "deployed" or "up"). It is just an example, my clients when they need to consume an endpoint from one microservice of mine do not use numbers, they use example.com.
so in the Keycloak when you want to see the metadata of the realm for SAML2.0 you can do it by following this link which is in the REALM settings section:
https://example.com/auth/realms/REALM-NAME/protocol/saml/descriptor
as you can see I am using "example.com" not "18.104.22.168:8082" to access the metadata link.
The problem is that inside the METADATA, the endpoints for SingleSignOnService, SingleLogoutService, etc. Are all configured to be "http://184.108.40.206:8082/auth/realms/REALM-NAME/protocol/saml" (notice it is using the numbers and not example.com) and this causes that when the clients that want to use SAML.
Send inside their SAML REQUEST "Destination" attribute like so: "http://example.com/auth/realms/REALM-NAME/protocol/saml" and this causes an invalid request error, with reason invalid_destination, because the request attribute Destination was expected to be:
"http://184.108.40.206:8082/auth/realms/REALM-NAME/protocol/saml" like is inside the Metadata.
So my question is, how can I edit the metadata to change the endpoints numbers to example.com or if that is not possible, how can I make example.com get translated to 220.127.116.11:8082 inside my keycloak server? Or if you know another way to solve/figure out this it is very welcome
Answer: I feel like a BEAST after finding out how to achieve what I needed after like 3 weeks of searching about keycloak and SAML (I overcame many obstacles this was the lastone), finally I managed to fix this by using the "Frontend URL" setting in my REALM settings, there I can put anything I want so that it changes "http://220.127.116.11:8082/auth/" (inside the metadata urls) for whatever I configure there, so for example if I set Frontend URL to:
https://example.com/auth/
now all my metadata endpoints will be like so:
https://example.com/auth/realms/REALM-NAME/protocol/saml
instead of:
http://184.108.40.206:8082/auth/realms/REALM-NAME/protocol/saml
now my client is being able to properly login with SAML2 using keycloak.
how did I manage to find out this? Well there is not much info so this was what gave me the hint: Keycloak behind nginx reverse proxy: SAML Integration invalid_destination
The person asking said that he configured frontend-url, and I wanted to give a try to that, and after checking if that changed metadata urls, surprise it did =)


"Estimated effects may be unbalanced" message when running aov in R. What does it mean?

Question: I am running a summary(aov(...)) in R and I got this message:
Estimated effects may be unbalanced

What does it mean? How may I solve this problem?
Answer: aov is designed for balanced data (link).  Balanced design is: An experimental design where all cells (i.e. treatment combinations) have the same number of observations (link).
Comment: I actually have faced the this is not necessarily true(Correct me if I am wrong). If you have an experiment with two factors.
`A<-factor(c(1,1,1,1,1,1,2,2,2,2,2,2))
B<-factor(c(1,1,2,2,3,3,1,1,2,2,3,3))
y<-rnorm(12)
aov(y~A+B)` gives the error prompt. We can see that all combination of levels A and B have equal replications , yet the "Estimated Effects may be unbalanced". I have a feeling that R compares the replication of levels of A with replications of levels of B.
Answer: Install package called car & activate it first and then calculate sum of squares using Anova(lm(y~x1*x2),type=2)
Doing this way will calculate type II SS which can be used for analysis when the interaction is not significant
and if the interaction is significant for the unbalanced data, you should calculate type III SS


Convergence of a sequence of real convex analytic functions

Question: This is a question on the convergence of a sequence of real, convex, analytic functions (it does not get better than that!):
Let $(f_n)_{n\in \mathbb N}$ be a sequence of convex analytic functions on $\mathbb R$.
Suppose that $f_n(x) \to f(x)$ as $n \to \infty$ for all $x \in \mathbb R$ (or in $\mathbb R^+$).
Is $f(x)$ analytic?
Answer: No—not even necessarily differentiable! The function $f_n(x) = \frac1n\log(1+e^{nx})$ is convex and analytic on $\Bbb R$, but
$$
\lim_{n\to\infty} \frac1n\log(1+e^{nx}) = \begin{cases} 0, &\text{if } x\le 0, \\ x, &\text{if } x\ge0.
\end{cases}
$$
Comment: Did you forget to divide by $n?$
Comment: @zhw Yes, thank you! Haha, I checked the limit graphically, but didn't notice the $y$-axis range was changing :D
Comment: Thanks! So I guess, the additional assumption that could make it work would be to add the constraint of  bounded derivatives.
Comment: In this and my example, the derivatives are bounded.
Comment: The derivative in 0 is actually growing with n in your example. I meant bounded with a constant K independent on n
Comment: No, check again: $|f_n'(x)|\le 1$  for all $n$ in my example.
Comment: Sorry, I expressed myself poorly... I meant derivatives of all order... the first one is finite, but the next ones grows with n.
Answer: Counterexample: Define $f_n(x) = (x^2+1/n)^{1/2}.$ Then each $f_n$ is analytic and convex on $\mathbb R.$ Clearly $f_n(x)\to |x|$ pointwise everywhere. (A little more work shows $f_n(x)\to |x|$ uniformly on $\mathbb R.$)
Comment: Great and simple example!


Computer getting Unable to Identify Network UNLESS Vlan is changed

Question: Question moved from Network Engineering to Server Fault.
This is a problem that has long plagued this environment.
At seemingly random times (measured generally in months), a computer may suddenly lose connectivity to the network.
It still is able to send packets through, reach and get an IP from the DHCP server, but it will simply fail to identify the network and display the yellow ! icon.
All the typical fixes - rebooting PC/port/switch, switching from DHCP to static or vise versa, changing ports, resetting NIC/winsock, reinstalling driver, etc. None of them will work.
But somehow, changing the access VLAN of the port will suddenly allow it to work. And seemingly nothing else. It doesn't have to be a VLAN it was on before, or even one that existed on the switch before. I think I found out by accident from completely wiping the port config and forgetting to put anything back.
This is of course, not a great solution or workaround and trying to search for the problem is kinda difficult given the far more commonplace issues with the same error.
I have seen this happen with Win 7 and some older machines. Possibly a Win 10 but I don't recall. Cisco Catalyst switches of various models. I've removed all but switchport mode access, and switchport access vlan ### from the switchport so it doesn't seem to depend on anything besides the vlan.
Comment: It sounds like a Layer 2 problem. Is it possible to have a MAC address issue? In the past I got some generic NICs with repeated MAC addresses.
Comment: As far as I could tell, not a MAC address issue. After all, then it would still have a problem even in a different VLAN.
Answer:
As far as I could tell, not a MAC address issue. After all, then it
would still have a problem even in a different VLAN.

You can have the same MAC in a different VLAN, you cannot have a duplicate MAC on the same VLAN though.  The MAC is at L2 and when you connect to a different system in a different VLAN, L2 doesn't traverse a L3 connection.
If it was a duplicate MAC, then even after changing the VLAN back to the original setting, you would still have the same issue.  When the problem does occur, can you take the MAC of that system and ask the L3 gateway for the ARP entry for that MAC?  Does the switch that the computer is on, does it show the correct port for the learned MAC address?


Why doesnt my migration plugin run?

Question: I made a plugin to add the alias to my node migration, using the instructions here https://www.calebthorne.com/blog/drupal/2016/07/16/drupal-8-migrate-pathauto
but i tried to put a drush break point and it never runs .  How do i get this plugin to run during the migration?  this is the plugin code below .  and the yml is as follows:
id: migd8_node_blog
label: Custom node migration from Drupal 7
migration_group: cncs
dependencies:
  enforced:
    module:
      - migd8_node_blog
source:
 plugin: d7_node
 node_type: blog_entry
destination:
  plugin: entity:node
  bundle: blog_entry
process:
  type:
    plugin: default_value
    default_value: blog_entry
  'path/alias': alias

migd8_node_blog/src/Plugin/migrate/source/Node.php
<?php

    /**
     * @file
     * Contains \Drupal\migd8_node_blog\Plugin\migrate\source\Node.
     */

    namespace Drupal\migd8_node_blog\Plugin\migrate\source;

    use Drupal\migrate\Row;
    use Drupal\node\Plugin\migrate\source\d7\Node as D7Node;

    /**
     * Custom node source including url aliases.
     *
     * @MigrateSource(
     *   id = "migd8_node_blog"
     * )
     */
    class Node extends D7Node {

      /**
       * {@inheritdoc}
       */
      public function fields() {
        return ['alias' => $this->t('Path alias')] + parent::fields();
      }

      /**
       * {@inheritdoc}
       */
      public function prepareRow(Row $row) {
        // Include path alias.
        $nid = $row->getSourceProperty('nid');
        drush_print_r($nid);
        $query = $this->select('url_alias', 'ua')
          ->fields('ua', ['alias']);
        $query->condition('ua.source', 'node/' . $nid);
        $alias = $query->execute()->fetchField();
        if (!empty($alias)) {
          $row->setSourceProperty('alias', '/' . $alias);
        }
        return parent::prepareRow($row);
      }
    }

Answer: Article is correct, just noticed that it's a source plugin and not a process plugin.
Change yours to
id: migd8_node_blog
label: Custom node migration from Drupal 7
migration_group: cncs
dependencies:
  enforced:
    module:
      - migd8_node_blog

source:
 plugin: migd8_node_blog_node # use custom node source plugin
 node_type: blog_entry

destination:
  plugin: entity:node
  bundle: blog_entry

process:
  nid: nid
  type: type
  'path/pathauto':
    plugin: default_value
    default_value: 0 # Disable pathauto.
  'path/alias': alias

And
/**
 * Custom node source including url aliases.
 *
 * @MigrateSource(
 *   id = "migd8_node_blog_node"
 * )
 */

Comment: i cleared cache again and imported again and it works now with your last suggestion. thanks
Comment: Like I said, change it to `migd8_node`. It might clash since you're already using `migd8_node_blog` as a migration ID, on line 1 of your yml file.
Comment: i did that now i get Drupal\Component\Plugin\Exception\PluginNotFoundException: The "migd8_node" plugin does not exist. Valid plugin IDs for          [error]
Drupal\migrate\Plugin\MigratePluginManager are: addressfield, block_plugin_id, etc.
Comment: Did you flush cache?
Comment: yes i did drush cr several times
Comment: My bad, I had your module name wrong, fixed.
Comment: @Diana Your module's name is `migd8_node_blog`, right? I'm assuming that based on the `namespace`.
Comment: yes that is the name of the module .  but now i get Drupal\Component\Plugin\Exception\PluginNotFoundException: The "migd8_node_blog_node" plugin does not exist. Valid plugin IDs for                   [error]
Drupal\migrate\Plugin\MigratePluginManager are: addressfield, block_plugin_id, block_region, block_settings, block_theme, block_visibility,
f
Comment: Did you place the Node.php file that you created in the `migd8_node_blog/src/Plugin/migrate/source/` folder?
Comment: yes that is exactly where it is.
Comment: @Diana updated the answer, should work now
Comment: i changed it to use the source as above , still get the same error source:
 plugin: migd8_node_blog_node # use custom source plugin
 node_type: blog_entry
Comment: still getting Drupal\Component\Plugin\Exception\PluginNotFoundException: The "migd8_node_blog_node" plugin does not exist. Valid plugin IDs for
Comment: Send me a screenshot of your module's folder structure, something is off. Worked fine for me.
Comment: i just added the correct screen shot .
Answer: fixed it by uninstalling and reinstalling the module and deleting the configuration.

Why doesnt my migration plugin run?


Prevent React from importing CSS files that are not being used yet

Question: Concerning page loading speed, It seems strange to me that React is importing CSS files that are imported in components that are not even being used on the homepage. My react app seems to be importing every css file in my entire project, i'm sure this is affecting my page speed. How can i prevent react from importing css files (which are being imported by components) that are not even being imported/exist on a certain page?
For example my homepage may have Comp1.js, comp2.js and comp3.js and each of these files import their own css files. But i see css files from other pages being loaded in the html head tag...(see screenshot below)
Comment: It would aid the community in understanding your issue if you could share how you are bundling your app.
Comment: What do you mean bundling my app? You want to see my folder structure?
Comment: I mean do you have a custom build using [webpack](https://webpack.js.org/) or [rollup](https://rollupjs.org/guide/en/) or some other build tool?  Or are you using the default build from [create-react-app](https://create-react-app.dev/)?  How are you styling your components?  Are you importing a CSS file into each of them?  Or are you using Sass, or styled components, or some other approach?  All this is necessary in understanding your particular scenario.
Comment: As i mentioned i am importing a css file into each jsx component. I am using create-react-app and using regular css to style my components.
Comment: Is this in your development environment?  This is typical when using CRA and webpack for dev; when you do a proper production build you would expect to see this optimized away.
Answer: const comp1 = await import('path');

Comment: While this code may answer the question, providing additional context regarding how and/or why it solves the problem would improve the answer's long-term value. You can find more information on how to write good answers in the help center: https://stackoverflow.com/help/how-to-answer . Good luck
Answer: I was having a similar issue, which led me to discover this question. Here's what worked for me:
Instead of importing the CSS files at the head of the component's source, you can import the file using import(<path>); in the render() function in case of class-based components, or before the return() statement in case of stateless functional components.
That way React won't be able to load the files at app's startup because their imports have been abstracted away by not being there in the top level structure of any component.
I'm just beginning to learn React so if anyone has a clearer explanation of how this works, I'll be more than happy to know.


Como acessar um array de forma circular?

Question: Considerando que eu tenha um array:
const a = ['A', 'B', 'C'];

Gostaria de criar uma função que retorne um item e, a cada chamada, retorne o subsequente, e ao chegar ao final, que retorne o primeiro novamente. Ou seja:

Chamada 1 retorna A;
Chamada 2 retorna B;
Chamada 3 retorna C;
Chamada 4 retorna A;
Chamada 5 retorna B;

E assim sucessivamente.
Answer:
AVISO
Relendo esta resposta dois anos depois, NÃO me parece um bom caso de uso para um iterator... Não tem nenhuma necessidade, é só firula sintática e provavelmente tem impacto na performance. Devo ter escrito isso como forma de estudar iterators na época, e para colocar mais um método de se fazer isso entre as respostas. Se eu fosse responder hoje, provavelmente sugeriria algo como o que sugeriu o Augusto Vasques ou o hkotsubo.
Então reforço o aviso: você provavelmente não precisa de um iterator para isso!!!

Parece um bom caso de uso para um iterator (criado aqui com uma generator function):

function* indiceArray(tamanho) {
    let indice = 0;
    while(true) {
        yield indice;
        indice = (indice + 1) % tamanho;
    }
    return indice;
}

const a = ['A', 'B', 'C']
const indice = indiceArray(a.length);

console.log(a[indice.next().value])
console.log(a[indice.next().value])
console.log(a[indice.next().value])
console.log(a[indice.next().value])
Comment: Eu fiz um benchmark por curiosidade e, realmente, a diferença de performance é drástica... [Ver aqui.](https://jsbench.me/l7ksispu3q/1) De todo modo, ainda acho que seja uma solução super interessante. Uma pena que a performance de iteradores ainda é ruim (e tendo em vista o que fazem deveria ser exímia). Espero que isso um dia melhore.
Answer: Uma alternativa é usar closures:

function makeCircular(arr) {
  var current = 0;
  return function() {
    return arr[current++ % arr.length];
  }
}

const a = ['A', 'B', 'C'];
let next = makeCircular(a);

// imprime A, B, C, A, B, C...
for(i = 0; i < 20; i++) {
    console.log(next());
}

makeCircular(a) recebe um array e retorna outra função, que por sua vez, retorna, a cada chamada, o próximo valor do array de maneira circular.
Você pode inclusive criar vários closures diferentes para o mesmo array, e cada um mantém seu estado individualmente:

function makeCircular(arr) {
  var current = 0;
  return function() {
    return arr[current++ % arr.length];
  }
}

const a = ['A', 'B', 'C'];
let next = makeCircular(a);
let next2 = makeCircular(a);

console.log(next()); // A
console.log(next()); // B
console.log(next2()); // A
console.log(next()); // C

Só um detalhe: o contador interno (current) pode dar problema se ele atingir o valor de Number.MAX_VALUE:

function makeCircular(arr) {
  var current = Number.MAX_VALUE; // começando em MAX_VALUE só pra mostrar o problema
  return function() {
    return arr[current++ % arr.length];
  }
}

const a = ['A', 'B', 'C'];
let next = makeCircular(a);

// imprime C 20 vezes
for(i = 0; i < 20; i++) {
    console.log(next());
}

No caso, imprimiu "C" 20 vezes, indicando que quando atingir MAX_VALUE, ele não consegue mais incrementar o valor (testei no Chrome e Firefox e o comportamento foi o mesmo).
Tudo bem que, segundo a documentação, o valor de MAX_VALUE é aproximadamente 21024, o que deve ser mais que suficiente para grande parte das aplicações.
Mas se quiser evitar esta - rara - situação, pode manter o valor de current sempre menor que o tamanho do array:

function makeCircular(arr) {
  var current = -1;
  return function() {
    current = (current + 1) % arr.length;
    return arr[current];
  }
}

const a = ['A', 'B', 'C'];
let next = makeCircular(a);

// imprime A, B, C, A, B, C...
for(i = 0; i < 20; i++) {
    console.log(next());
}

Generalizando a solução
Por fim, dá para generalizar esta solução para avançar uma quantidade arbitrária de elementos, em vez de pegar sempre o próximo. Além disso, daria para setar também a posição inicial:

// para módulo funcionar com números negativos
function mod(n, m) {
    return ((n % m) + m) % m;
}

// default é começar do primeiro elemento, e avançar de 1 em 1 (funciona igual à solução anterior)
function makeCircular(arr, start = 0, step = 1) {
    var first = true;
    var current;
    return function () {
        if (first) {
            first = false;
            current = mod(start, arr.length);
        } else {
            current = mod(current + step, arr.length);
        }
        return arr[current];
    }
}

const a = ['A', 'B', 'C', 'D', 'E'];
let next = makeCircular(a, 0, 8); // começa do primeiro, avança de 8 em 8
// imprime A, D, B, E, C, A, D...
for (i = 0; i < 10; i++) {
    console.log(next());
}

// ou, com passos negativos
console.log('com passo negativo');
next = makeCircular(a, 2, -8); // começa do terceiro, retrocede de 8 em 8
// imprime C, E, B, D, A, C...
for (i = 0; i < 10; i++) {
    console.log(next());
}

console.log('com índice inicial negativo');
next = makeCircular(a, -1, 2); // começa do último, avança de 2 em 2
// imprime E, B, D, A, C, E...
for (i = 0; i < 10; i++) {
    console.log(next());
}

Só tive que fazer um ajuste para o módulo quando há números negativos envolvidos, já que em JavaScript -1 % 5 é igual a -1, mas no nosso caso precisaria que fosse 4 (ler aqui pode ajudar a entender).
Desta forma, é possível usar tanto o passo quanto o índice inicial negativo (por exemplo, start igual a -1 começa do último elemento, -2 de penúltimo, etc; e para um array com 5 elementos, start igual a -6 também começaria do último).
Answer: A seguinte função retorna o item subsequente a cada chamada

var arr = ["A", "B", "C"];

function getItem(arr) {
    arr.push(arr.shift());
    return arr[arr.length - 1];
}

console.log(getItem(arr));
console.log(getItem(arr));
console.log(getItem(arr));
console.log(getItem(arr));
console.log(getItem(arr));

O funcionamento é baseado em pilha. O primeiro elemento do array é sempre removido e colocado na ultima posição, ou seja, no topo. A cada chamada da função, a estrutura do array é atualizada por meio do arr.push() responsável por empilhar o primeiro elemento removido pela função arr.shift().
Referência
Comment: @Sorack removidos :)
Comment: E aquele `alert`, o `slice` e o `join` são pra que?
Answer: Uma alternativa seria também dispor a opção de definir um limite para a sua função, isto é, repetir os valores do array até uma determinada quantidade. Para isso, você poderia definir um gerador e controlar a quantidade de itens já retornados anteriormente:
function* repeat(array, n = Infinity) {
    loop: while (true) {
        for (const item of array) {
            if (!n--) {
                break loop;
            }

            yield item;
        }
    }
}

Assim, fazendo repeat([1, 2, 3]) irá repetir os três valores infinitamente, mas se você atribuir um limite em n, repeat([1, 2, 3], 5), irá repetir até gerar cinco valores, [1, 2, 3, 1, 2].

function* repeat(array, n = Infinity) {
  loop: while (true) {
    for (const item of array) {
      if (!n--) {
        break loop;
      }

      yield item;
    }
  }
}

const items = repeat([1, 2, 3], 5);

for (const item of items) {
  console.log(item);
}
Answer: Se não quiser perder tempo:
Para fazer um array usar índices circulares ao final basta usar a fórmula:
indíce normalizado = resto(indice estrapolado, comprimento da array)
Lembrando que resto em JavaScript é %.

const arr = ['A', 'B', 'C'];

const len = arr.length;

for (i = 0; i < 10; i++) {
  console.log("arr[" + i + "]= " + arr[i % len]);
}
Answer: Bom vou entrar no jogo também e sugerir adicionar uma propriedade não interável ao seu array:

function adicionaNext(obj) {
  Object.defineProperty(obj, 'next', {
    value: (i => function() { return this[i++ % this.length] })(0)
  })
}

const arr = ['A', 'B', 'C']
adicionaNext(arr)

console.log(arr.next())
console.log(arr.next())
console.log(arr.next())
console.log(arr.next())
console.log(arr.next())
Answer: Usando closures, é possível gerar uma função foo que, sempre que invocada, retorna o próximo elemento do array, ainda que ele seja modificado no decorrer do código.

function getElement(list) {
    if (!Array.isArray(list)) {
        throw new Error('list deve ser array.');
    }

    let index = list.length - 1;

    function next() {
        index = (index + 1)%list.length;
        return list[index];
    }

    return next;
}

const a = ['A', 'B', 'C'];
const foo = getElement(a);

// testando
console.log('a = ', a);
for (var i = 0; i < 10; i++) {
    console.log(foo());
}
console.log('inserindo D');
a.push('D');
console.log('a = ', a);
for (var i = 0; i < 10; i++) {
    console.log(foo());
}
console.log('deletando B, C');
a.splice(1, 2);
console.log('a = ', a);
for (var i = 0; i < 10; i++) {
    console.log('->', foo());
}


how to display $page array?

Question: How to display the entire $page array like shown below?
I have devel module installed and have tried "dsm($page)" but that just shows the word "Array".
Comment: If `dsm($page)` just shows an array, then the variable named `$page` in that context is an empty array. Either that or you have a broken version of Devel/Krumo. Or, you haven't actually called `dsm()`, but `drupal_set_message()`, which is an altogether different function, and doesn't format arrays/objects automatically
Answer: You can try dsm($page) in page.tpl.php of your theme to see the contents of $page array.
As mentioned by Clive, context really matters. If you will try to print $page array when it has no elements then it will display word Array.

how to display $page array?