recharts add close button across each bar in MultiBarChart along Y-axis in order to close the bars

Question: I need to add a cross button along each bar which is being displayed against Y-axis, which will be helpful for users to close the bars. I am following vertical layout, bar would be placed along Y-xis. I tried to add it using LabelList but not able to achieve it. Can someone suggest me how can this be achieved?
Comment: Can you share a code sandbox or codepen with your code so far?
Comment: Thanks, I found out the solution to my problem.It has been explained on recharts site link to the same is http://recharts.org/en-US/guide/customize.
Answer: It seems like what you're trying to do is create a custom tickFormatter along the y-axis. You said you've tried to add the cross using LabelList - have you tried using tickFormatter to create a custom tick that can be displayed? I would personally play around with that until I got it showing up the way I wanted it.
Then, I would think of what I would need to do to get the bars to "close" when a user clicks on the cross icon.
Would I just do a display none? Would I use Array.prototype.splice to remove it at a specific index?
I would take a closer look at the Y-Axis documentation for recharts here ---> http://recharts.org/en-US/api/YAxis
and I would also suggest looking at the customized bar chart event to see how their onClick is being used ---> http://recharts.org/en-US/examples/BarChartWithCustomizedEvent
I think instead of using LabelList, you should try to use tickFormatter, because from what it seems with LabelList, it's meant to be used on a bar component ---> http://recharts.org/en-US/api/LabelList
While with tickFormatter, that would be affecting the ticks that are on the side of the chart and you could format it so the ticks don't show the numbers but it shows the cross icon as you mentioned and then create a custom tooltip to display the numbers.
I hope this wasn't too long and confusing and was somewhat helpful :)
Comment: Thanks, I found out the solution to my problem.It has been explained on recharts site,  link to the same is http://recharts.org/en-US/guide/customize.


PHP's in_array function not working correctly with XML

Question: The code below is being used to retrieve the value of the "store" element from the XML file below and insert the values into an array (the storeArray). I do NOT want duplicate value put into the array (IE I don't want Best Buy inserted twice), so I am using the in_array method
to prevent duplication.
This code does not prevent duplication (IE Best Buy is displayed twice):
$xmlDoc = simplexml_load_file("products.xml");
$storeArray = array();

foreach($xmlDoc->product as $Product) {
    echo "Name: " . $Product->name . ", ";
    echo "Price: " . $Product->price . ", ";

    if( !in_array( $Product->store, $storeArray )) {
        $storeArray[] = $Product->store;
    }
}

foreach ($storeArray as $store) {
    echo $store . "
";
}

But this code does work:
$practiceArray = array('Product1', 'Product2', 'Product3');

if (in_array("Product1", $practiceArray)) {
    echo "Is in array";}
else {
    echo "NOT in array";
}

Any advice?
Here is the XML file:
<products>

<product type="Electronics">
<name> Desktop</name>
<price>499.99</price>
<store>Best Buy</store>
</product>

<product type="Electronics">
<name>Lap top</name>
<price>599.99</price>
<store>Best Buy</store>
</product>

<product type="Hardware">
<name>Hand Saw</name>
<price>99.99</price>
<store>Lowes</store>
</product>

</products>

Answer: Try to do this
if( !in_array( (string)$Product->store, $storeArray )) {
    $storeArray[] = (string)$Product->store;
}

because $Product->store is not a string: it's a SimpleXMLElement object. So you should cast it as string before its manipulation.
Comment: What variable type could it be cast initially besides string?
Comment: @SetSailMedia you can cast any type (array) (bool) (string)... the problem is if the result is what you expected. :)
Comment: How does `in_array()` scores when `$storeArray[]` grows larger?


Uniqueness of QR decomposition of rank n-1 matrix

Question: Say if I have a matrix $A$ whose first $n-1$ columns are linearly independent, and the nth column is a linear combination of the previous $n-1$ columns. Is the QR decomposition also uniquely determined in this case? Here's my reasoning:
If we look at the first $n-1$ columns of $Q$ and $R$, they are definitely unique, but then the last column of $Q$ is also uniquely defined. Then the last column of $R$ must have $0$ as the last element and the previous $n-1$ elements are defined by the linear combination. So in summary everything seems to be uniquely defined.
Answer: I assume $A$ is square and you are doing the standard $QR$ factorization associated with square matrices -- i.e. $Q$ and $R$ are both square.  (The fact that there are ways to do this without $Q$ and $R$ both being square is a red flag that this isn't going to be unique).
Let $D$ be a diagonal matrix with all ones on the diagonal, except the bottom right entry is $-1$.
$A=QR = Q\big(I\big)R =Q\big(DD\big)R = \big(QD\big)\big(DR\big)=\big(QD\big)R$
But $Q\neq QD$ so it is not unique.
Comment: So basically it's not unique because of the ambiguity of the sign of the last column of Q? Then I think it's hard to make a clear cut -- even for full rank matrices we ignore the sign ambiguity by assuming positive diagonals in R. But we have a zero here so, I guess yeah...
Comment: incidentally, same idea with Polar Decomposition https://math.stackexchange.com/questions/3834754/how-to-show-that-the-unitary-matrix-in-a-polar-value-decomposition-a-up-is-uni/3834827  .  I generally wouldn't expect uniqueness when dealing with singular matrices.


How to create a DialogPreference programatically?

Question: The background of my question is that I'd like to create a menu just like the "Wifi Networks" settings on my Samsung Galaxy S9000. The menu shows a list of known networks and has one additional list entry with the title "Add new network". If you click on it, fill out the dialog and hit "Ok" you get a new list item. The "Add new network" item is still there after this procedure.
My approach is to have a PreferenceScreen with one AdressDialogPreference which is a subclass of DialogPreference. The title of this preference is set to "Add new IP Address". When the user opens the dialog and enters values, the title of the AddressDialogPreference changes from "Add new IP Address" to the value the user entered in the dialog, e.g. "192.168.1.1".
But now I need a new AddressDialogPreference with the title "Add new IP Address", because the user may want to add more ip addresses. That is where I'm stuck. I tried the following:
@Override
protected void onDialogClosed(boolean positiveResult) {

    if(!positiveResult)
        return;

    (...)

    PreferenceScreen ps = (PreferenceScreen)pm.findPreference("validIPs");
    ps.addPreference(new AddressDialogPreference(getContext(), attr ));
}

But I have no idea where I can get/create an appropriate AttributeSet (the  attr parameter). I cannot write a constructor without the AttributeSet because the base class DialogPreference requires an AttributeSet.
I tried to create an AttributeSet via Xml.asAttributeSet(XmlPullParser) but I have no clue what to feed to the XmlPullParser. The attributeCount was always -1 which is obviously wrong. The whole approach via a parser seems to me way to complicated.
The target API level is 8.
Excerpt from preferences.xml:
<PreferenceScreen android:title="@string/validIPsHeadline"
android:summary="@string/validIPsSummary"
android:dependency="restrictIPs"
android:key="validIPs">

<com.websliders.preferences.AddressDialogPreference
android:title="@string/defaultIPHeadline"
android:summary="@string/defaultIPSummary" />
</PreferenceScreen>

Answer: I'm not sure if this is relevant but this is how I loaded an AttributeSet into a SeekBarPreference (from http://android.hlidskialf.com/blog/code/android-seekbar-preference ), which is also derived from the DialogPreference class.
In your PreferenceActivity:
public PreferenceScreen getPreferenceScreen(String title, String summary) {
    // Root
    PreferenceScreen root = getPreferenceManager().createPreferenceScreen(this);

    PreferenceCategory inlinePrefCat = new PreferenceCategory(this);
    inlinePrefCat.setTitle("DNA");
    root.addPreference(inlinePrefCat);

    //This is where you load the AttributeSet
    //from the res/layouts/seekbarpreference_layout.xml file
    Preference editTextPref;
    Resources resources = this.getResources();
    XmlPullParser parser = resources.getXml(R.layout.seekbarpreference_layout);
    AttributeSet attributes = Xml.asAttributeSet(parser);

    editTextPref = new SeekBarPreference(this, attributes);

    editTextPref.setKey(title);
    editTextPref.setTitle(title);
    editTextPref.setSummary(summary);
    //editTextPref.setText(text)
    inlinePrefCat.addPreference(editTextPref);

    return root;
}

And this is the "res/layouts/seekbarpreference_layout.xml" file:
    <?xml version="1.0" encoding="utf-8"?>
<com.hlidskialf.android.preference.SeekBarPreference
        xmlns:android="http://schemas.android.com/apk/res/android"
         android:key="duration"
        android:title="Duration of something"
        android:summary="How long something will last"
        android:dialogMessage="Something duration"
        android:defaultValue="5"
        android:text=" minutes"
        android:max="60"
        />

If it's not working for you, perhaps you are missing a required attribute in the XML file?


grabbing data and displaying it in block twig

Question: bI made a custom module and made a custom block inside of it.
In the build () I have this.
return array (
  '#theme' => 'no_athlete_match_block',
  '#title' => 'Athletes With No Matching Name in the Database',
  '#description' => 'Displays the athletes with no matching name in the database for a given sporting event.',
);

In the .module file I have this.
function no_athlete_match_theme($existing, $type, $theme, $path) {
  return array(
    'no_athlete_match_block' => array(
      'variables' => array(
        'description' => NULL,
        'title' => NULL
      ),
      'template' => 'block--no_athlete_match',
    ),
  );
}

my twig file named block--no-athlete-match.html.twig

node: {{title}} {{description}}

Only Node: shows up. If I do dump(title) I get NULL to show up. Not sure what I'm missing. I've copied other blocks and still nothing.
Answer: Because you've specified the template parameter in the hook_theme function the template file name should be exactly as specified block--no_athelete_match.html.twig. The underscores are converted to dashes only in the case where the template parameter is not specified in the hook_theme function.
Comment: .tpl is for drupal 7. Do you mean .twig?
Comment: yeah, sorry about that. I updated the file name.
Answer: In your module file the suggestion of template will be only with underscores.
block__no_athelete_match
and in templates folder template name  needs to be only with dashes.
block--no-athelete-match.html.twig
Comment: That makes sense and I made the change but it still doesn't work after rebuilding cache.
Answer: So having playing around with it for two days I ended up commenting out template and listening to the twig debug recommendations. I then added the path so that I could have the template in my module folder. It might not be the best way to do this but it's working.
My module function
function no_athlete_match_theme($existing, $type, $theme, $path) {
return array(
 'no_athlete_match_block' => array(
          'variables' => array(
              'dsp' => NULL,
              'title' => NULL,
          ),
       //  'template' => 'no-athlete-match',
         'path' => drupal_get_path('module', 'no_athlete_match') . '/templates'
      )
);

}
My block file
 return array (
            '#theme' => 'no_athlete_match_block',
            '#title' => 'Athletes With No Matching Name in the Database',
            '#description' => 'Displays the athletes with no matching name in the database for a given sporting event.',
            '#dsp' => $output,
        );

My Twig file.

            Player
            Query

            {{dsp.player}}
            {{dsp.notes}}


How to validate HTML pages with R?

Question: I have a list of URLs (large enough) and I want to check whether their HTML code is valid. If it is not, I want to know the number of errors and warnings like the results of this page: http://validator.w3.org/
Therefore, via R I want to submit my URLs to that webpage and then parse the results to get the information I need. Is there another way of doing it?
I've found the RCurl package but I'm not really sure how to go for it. I'll appreciate any help.
Thanks in advance.
Edit:
I tried the following code which seems to kind of do the job although I still cannot process some URLs for some unknown reason for which I get an error and the code stops (therefore I lose everything).
HTMLValid=foreach(i=1:nrow(allData), .combine='rbind') %dopar% {
  library(RCurl)
  library(XML)
  url=paste("http://validator.w3.org/check?uri=",
            as.character(allData$url[i]),
            "&charset=%28detect+automatically%29&doctype=Inline&group=0#preparse_warnings",
            sep="")
  w = getURL(url,httpheader = c('User-Agent' = "Mozilla/5.0 (Windows NT 6.1; rv:23.0) Gecko/20100101 Firefox/23.0"))

  doc <- htmlTreeParse(w, getDTD = F)
  r=xmlRoot(doc)
  text=r[["body"]][[2]][[4]][[1]][[1]][[2]][[1]]
  errors=strsplit(toString.XMLNode(text),' ')[[1]][1]
  warnings=strsplit(toString.XMLNode(text),' ')[[1]][3]

  c(as.numeric(errors),as.numeric(warnings))
}

Probably I get errors when the page doesn't respond within a specific timeframe. How can I overcome this? Is there a way to do the procedure faster?
Comment: You might try `xmlSchemaValidate` from `library(XML)`.
Comment: You can specify the foreach `.errorhandling='remove'` option in order to filter out errors and only return the task results that succeeded.  In that way, you avoid losing everything when a few tasks fail.
Comment: @SteveWeston This way I won't be able to identify the cases for which I didn't get the results. Or maybe I could append the iterator in the results!!

Thomas I'll give it a try! Thanks!!
Comment: @Thomas I can't make it work for HTML files that are already saved on my pc. Do you have any working code?
Comment: I've never actually tried it for HTML (as opposed to other XML), so I don't have specific recommendations.
Comment: @Thomas A lot of valid HTML is invalid XML. My guess is that a schema validator copes very badly with that.
Answer: Some comments on your code.
You probably should not load your libraries inside your for loop. I'm not sure this would cause crashes but you should only load your libraries once.
More importantly, do not parallelise your web scraping. There are three reasons for this:
1) I do not see that you processing power will be the bottleneck here so you probably won't gain any performance by parallelising.
2) The errors might come from your making too frequent requests to the website and it "throws you out".
3) You are not collecting results as they come so that you lose all previously obtained results.
A simple fix: use a normal for loop, preferably with some timer inside to ensure you are not making too many requests per second. Save your results to a list at each step of the loop (incrementing your list's size).
If it still gets an error eventually, at least you'll have stored previous results and you'll know at which point it crashed (so you can rework that single example by hand and see what went wrong).
Another possibility would be to enclose the inside of your loop in a tryCatch in order to skip the cases where it throws an error and continue regardless.
Here is your reworked code. I have not run it.
library(RCurl)
library(XML)
results <- list()
for (i=1:nrow(allData)) {

  Sys.sleep(1)

  try({
  url=paste("http://validator.w3.org/check?uri=",
            as.character(allData$url[i]),
            "&charset=%28detect+automatically%29&doctype=Inline&group=0#preparse_warnings",
           sep="")
  w = getURL(url,httpheader = c('User-Agent' = "Mozilla/5.0 (Windows NT 6.1; rv:23.0) Gecko/20100101 Firefox/23.0"))

  doc <- htmlTreeParse(w, getDTD = F)
  r=xmlRoot(doc)
  text=r[["body"]][[2]][[4]][[1]][[1]][[2]][[1]]
  errors=strsplit(toString.XMLNode(text),' ')[[1]][1]
  warnings=strsplit(toString.XMLNode(text),' ')[[1]][3]
  results[[i]] <- c(as.numeric(errors),as.numeric(warnings))
  })
}

Results <- do.call("rbind", results)

How to validate HTML pages with R?


Finding $(x, y)$ as a function of $n$ radians

Question: For a joystick thing in a game, I need to find where a line with an angle of $n$ radians intersects with a square of width and height of $2$ around the joystick with a radius of 1.

Right now I have a simple sin cos function that only gets the coordinates on the circle and not the square.
$$
f(n) = [\sin(n), \cos(n)]
$$
What function is used to find a vector of $x$ and $y$ as a function of $n$ radians that is on the square?
Comment: some angles could be wrong in the image but right is 0 radians and i made it in ms paint
Answer: The ray's intersection with the square will naturally depend on what side it intersects:
$$\begin{cases}
(1,\tan n)&-\frac\pi4\le n\le\frac\pi4\\
(\cot n,1)&\frac\pi4\le n\le\frac{3\pi}4\\
(-1,-\tan n)&\frac{3\pi}4\le n\le\frac{5\pi}4\\
(-\cot n,-1)&\frac{5\pi}4\le n\le\frac{7\pi}4
\end{cases}$$
This is done by taking $(\cos n,\sin n)$ (the order in the question body is wrong if it refers to $(x,y)$-coordinates) and then dividing by the larger coordinate to make it $\pm1$, leaving the transformed point on the square itself. The cases can be unified as
$$\left(\operatorname{clip}_{-1}^1\left(\frac{\cos n}{|\sin n|}\right),\operatorname{clip}_{-1}^1\left(\frac{\sin n}{|\cos n|}\right)\right)$$
with $\operatorname{clip}_a^b(x)$ referring to clipping $x$ between $a$ and $b$ and equal to $\min(\max(a,x),b)$. This can be further simplified to
$$\frac{(\cos n,\sin n)}{\max(|\cos n|,|\sin n|)}$$
Comment: is there a simpler version of the clip function because im doing it with javascript and i dont want to implement it
Comment: @GiantBooley Clip is very easily implementable in JS (or C) using min/max: `min(max(a,x),b)`.
Comment: @peterwhy Right. I forgot to add some signs.
Answer: While $(\cos n, \sin n)$ in the question gives the unit circle, expanding the circle by a suitable factor $r(n)$ (which depends on $n$) gives the square.
The factor $r(n)$ is related to $\sec n$ and $\csc n$:
$$\begin{align*}
r(n) &= \min\left(\left|\sec n\right|, \left|\csc n\right|\right)\\
&= \frac{1}{\max\left(\left|\cos n\right|, \left|\sin n\right|\right)}
\end{align*}$$
Then the point on the square would be
$$\begin{align*}
f(n) &= r(n)\cdot(\cos n, \sin n)\\
&= \left(\frac{\cos n}{\max\left(\left|\cos n\right|, \left|\sin n\right|\right)}, \frac{\sin n}{\max\left(\left|\cos n\right|, \left|\sin n\right|\right)}\right)
\end{align*}$$


A quiz question based on matrices over $\Bbb C$

Question: I am trying previous years questions of my linear algebra exam and I was unable to solve this particular question.

State True/False with reasoning: Let $A$ belong to $M_{n \times n}(\mathbb{C})$. Then:

There exists a matrix $B$ belonging to $M_{n \times n}(\mathbb{C})$ such that $B^{2}=A$.
There exists an invertible  matrix  $P$ such that $PAP^{-1}$ is upper triangular.

For 1. I could think of comparing both sides but that is feasible for only $2 \times 2$ matrices.
For 2. I have no idea on which result I should use .
Any hints would be really appreciated .
Comment: For $2$, have you seen quotient spaces? Use the fact that every operator on a complex-vector space must have an eigenvector, quotient out by the space spanned by such eigenvector, and continue inductively.
Answer:
Consider $$A=  \begin{pmatrix} 0 & 1 \\ 0 & 0 \end{pmatrix}$$

If there exists $B$ such that $B^2=A$, then $B^4=A^2=0$, so $B$ is nilpotent, but $B$ has size $2$, so $B^2=0$, so $A=0$. This is absurd.

This is very classical, see for example : https://en.wikipedia.org/wiki/Triangular_matrix#Triangularisability
Answer: Hints:

Consider what happens when you take determinants.

Have you ever come across Jordan Canonical Form?
Comment: We are given a generic $n \times n$ matrix, and asked if a square root always exists. Using that the determinant is multiplicative should guide towards straightforward counterexamples
Comment: But in point of fact the only such counterexamples are in some special instances of the case $\det A=0$.
Comment: Perhaps I require another coffee, but what if $A$ were to have negative determinant? The criterion you suggest seems unreasonable for any examiner to assume of their linear algebra students.
Comment: Yes, you're quite right. I won't delete my answer as I hope this discussion is useful. Hopefully you or another commenter can provide a clearer answer.


Is a repeated measures t-test appropriate for this scenario?

Question: I am working with a dataset that involves participants taking a baseline test and a post-test. The company I am working with has the mean baseline score for participants from a year ago, and they would like me to run a repeated measures t-test using the old baseline score means. There are now new participants who have taken a post-test, but no baseline test (which is where the means come in.) Basically, the data is structured as so:

Because of this, the standard deviation for the Baseline scores is zero. Can I still run a repeated measures t-test on this dataset? Is there a better-suited test I should be running? I cannot share the dataset because the company has asked me not to share it. In case this helps, I am using R for data analysis.
Answer: I have no idea what you mean by a "repeated measures" t test in this situation.
The terminology "repeated measures" has been used so carelessly in so many
different contexts that it has become meaningless.
If you have a baseline test and a post test for for each subject and if the differences between baseline and post test are normally distributed, then you need
a paired t test. In that case, a paired t test amounts to a one-sample t test on
the differences with the hull hypothesis being $0$ difference on average.
If you are comparing normally distributed 'post-test' scores with an average from previous years (presumably for a population of subjects that is comparable with the current ones), then you need a one-sample t test with the established mean from pervious years as the hypothetical value.
If you are permitted to give a clearer description of (a) whom you have tested and under what circumstances and (b) what you want to find out from your data, then maybe
one of us can be of more help.


Fix a constant width for first sidebar and second sidebar

Question: I'm working on Zero point Theme in drupal 7. In my home page I've three blocks - first sidebar, content and second sidebar formatted as three columns. Here the width of first sidebar and second sidebar are equal and the content has its own width (I'm ok with that). There are some pages where I have only first sidebar and content.
Previously, I was facing a problem like if I go to other pages(other than home-page) the first sidebar's width will be increased. I don't like the view so I changed the CSS.
I gave a fixed width to the blocks by editing the CSS -
.block.themed-block{
                    width: 60%;
                   }

Now, the first sidebar and second sidebar has constant width in all pages.
My Issue is : when I go to other pages where I have only first sidebar and content page, the width of the first sidebar is reduced and the content part doesn't appear from where the first sidebar ends, it leaves some space between the first sidebar and the content part. It shows some odd effect. I want the content part to start from where the first sidebar ends. Is there any way to get rid of that.
Below, I share the screenshot of my Issue.

Highlighted rectangle part is the space, that I want to get rid of.
Answer: My guess, before your css editing, the index block filled that white space, right?
you changed the width of the sidebar's content, rather than the sidebar itself (which is a region, not a block)
i don't know of the zero point theme, but look for an outer class, like .sidebar, or .sidebar-first, and set the with of that.

i looked into that particular theme.
revert all the css editing and go to the theme settings, under "layout setting -> sidebars layout" try using the 'fixed' options instead than the 'variable'.
Comment: I was trying to find .sidebar or .sidebar-first in my theme folder. But I couldn't any of such kind.
Comment: yes, got you.. found the class names through firebug lite. Just changed those in CSS.
Comment: Hey no, it works fine on pages that contains sidebar and content. If there is only content, the content part moves out of the page border.
Comment: Is There any other way to move the content towards left.
Comment: After Edit : that was awesome, it works. I should really thank you.


Getting "No signature of method:" error while updating the request xml using groovy

Question: Trying to update request XML using groovy script. Error is coming on the last line. Below is the script:
import com.eviware.soapui.support.XmlHolder

def request=testRunner.testCase.testSteps["SOAP Request - CurrencyCheck"].getPropertyValue("Request")

def groovyProgram=new XmlHolder(request)

def currency =testRunner.testCase.testSuite.getPropertyValue("Currency")
def country = testRunner.testCase.testSuite.getPropertyValue("Name")

groovyProgram.setNodeValue("//web:CountriesUsingCurrency/web:sISOCurrencyCode",currency)

def newxml=groovyProgram.getXml()
testRunner.testCase.testSuite.testCases("TC2_CurrencyCheck").testSteps("SOAP Request - CurrencyCheck").setPropertyValue("Request",newxml)

Answer: If you're targeting specific test cases and test steps, you'd need to use the get...ByName methods. For example:
testRunner.testCase.testSuite
         .getTestCaseByName("TC2_CurrencyCheck")
         .getTestStepByName("SOAP Request - CurrencyCheck")
         .setPropertyValue("Request", newxml)

I assume you're also getting a similar error for your first statement def request=testRunner.testCase.testSteps["SOAP Request...


Getting '#default_value' from $form

Question: I have this code:
<code>$form['custom'] = array(
'#title' => t('Some title'),
'#type' => 'select',
'#options' => $custom,
'#default_value' => isset($option->name) ? $option->name_id : '',
'#description' => t('Some text goes here.'),
</code>
Now when i do print_r i get data from option and the name_id of the selected one.
No how can i get this data (name_id) from "#default_value" ??
In submit function i have this:
<code>$custom=$form_state['values']['custom'];
</code>
But this only gets me the name not the name_id .
Answer: You can get it from the form itself:
<code>$custom = $form['custom']['#default_value'];
</code>
Comment: O thank a million , my brain frozen i couldnt think any more. I done it before but just couldn't think it. You the man :).

Getting '#default_value' from $form


What is the meaning of the axes in t-SNE?

Question: I'm currently trying to wrap my head around the t-SNE math. Unfortunately, there is still one question I can't answer satisfactorily: What is the actual meaning of the axes in a t-SNE graph? If I were to give a presentation on this topic or include it in any publication: How would I label the axes appropriately?
P.S: I read this Reddit question but the answers given there (such as "it depends on interpretation and domain knowledge"), don't really help me to understand this.
Answer: Individual axes in t-SNE have no meaning at all.
Algorithms such as MDS, SNE, t-SNE, etc. only care about pairwise distances between points. They try to position the points on a plane such that the pairwise distances between them would minimize a certain criterion. This means that if you take a t-SNE plot and rotate it, then the resulting arrangement will be equally good as far as t-SNE is concerned. So the overall rotation that you get out of t-SNE algorithm is arbitrary.
To label the axes, I recommend writing something like "t-SNE dimension 1" and "t-SNE dimension 2".
(Sometimes people write "t-SNE 1" and "t-SNE 2" or some such, which is sloppy. Sometimes I see "t-SNE component 1" and "t-SNE component 2"; but I think that the word "component" does not work very well in this context.)
Comment: Another corollary to this answer is that the axes should be displayed on the same scale, so that if you multiplied by a [rotator matrix](http://mathworld.wolfram.com/RotationMatrix.html) and tilted your head correspondingly, the plot would look exactly the same. This is sadly far from standard practice (grumble!).
Comment: A corollary to this answer is that the Reddit suggestion is a little wrong. There probably isn't a reasonable way to interpret the axes in general, even if you have domain knowledge to apply.


Count Frequency based on Bit Flag

Question: SELECT

              ROW_NUMBER() OVER (PARTITION BY dicei.IsLocked ORDER BY DocumentInstanceChapterExpanded.PK_DocumentInstanceChapterExpanded)
             ,DocumentInstance.PK_DocumentInstance
             ,DocumentInstanceChapterExpanded.PK_DocumentInstanceChapterExpanded
             ,dicei.IsLocked

FROM         DocumentInstance INNER JOIN
                      DocumentInstanceChapter ON DocumentInstance.PK_DocumentInstance = DocumentInstanceChapter.FK_DocumentInstance INNER JOIN
                      DocumentInstanceChapter AS DocumentInstanceChapter_1 ON
                      DocumentInstanceChapter.PK_DocumentInstanceChapter = DocumentInstanceChapter_1.FK_DocumentInstanceChapter INNER JOIN
                      DocumentInstanceChapterExpanded ON
                      DocumentInstanceChapter_1.PK_DocumentInstanceChapter = DocumentInstanceChapterExpanded.FK_DocumentInstanceChapter INNER JOIN
                      DocumentInstanceChapterExpanded AS DocumentInstanceChapterExpanded_1 ON
                      DocumentInstanceChapter.PK_DocumentInstanceChapter = DocumentInstanceChapterExpanded_1.FK_DocumentInstanceChapter INNER JOIN
                      DocumentInstanceChapterExpandedItem AS dicei ON
                      DocumentInstanceChapterExpanded.PK_DocumentInstanceChapterExpanded = dicei.FK_DocumentInstanceChapterExpanded
WHERE     (DocumentInstance.PK_DocumentInstance = 455)
 AND DocumentInstanceChapterExpanded_1.PK_DocumentInstanceChapterExpanded = 50730

As you can see the picture what i wanted to do was add a Column which would indicate
**Result Expected**
ExpandeditemKey IsLocked     StatusColumn
50797               0         Mixed
50797               0         Mixed
50797               1         Mixed
50797               1         Mixed
50797               1         Mixed
50798               1         Lock
50798               1         Lock
50798               1         Lock

If it contains 0 and 1 'Mixed'
If it contains 1 only  'Lock'
If it contains 0 only  'Unlock'

it does not necessary need to be string column, i tried using OverBy Clause if i can used Partition by for the Islock Bit Field but was not able to
Thanks for having a look.
Answer: I suggest usng MIN/MAX as window functions, then you can add a case expression that works across a partition. e.g.
SELECT
      ROW_NUMBER() OVER (PARTITION BY dicei.IsLocked ORDER BY DocumentInstanceChapterExpanded.PK_DocumentInstanceChapterExpanded)
    , DocumentInstance.PK_DocumentInstance
    , DocumentInstanceChapterExpanded.PK_DocumentInstanceChapterExpanded
    , dicei.IsLocked
    , case when dicei.isLockedMin <> dicei.isLockedMax then 'Mixed'
           when dicei.isLockedMax = 0 then 'Unlocked'
           else 'Locked'
      end StatusColumn
FROM DocumentInstance
INNER JOIN DocumentInstanceChapter ON DocumentInstance.PK_DocumentInstance = DocumentInstanceChapter.FK_DocumentInstance
INNER JOIN DocumentInstanceChapter AS documentinstancechapter_1 ON DocumentInstanceChapter.PK_DocumentInstanceChapter = documentinstancechapter_1.FK_DocumentInstanceChapter
INNER JOIN DocumentInstanceChapterExpanded ON documentinstancechapter_1.PK_DocumentInstanceChapter = DocumentInstanceChapterExpanded.FK_DocumentInstanceChapter
INNER JOIN DocumentInstanceChapterExpanded AS documentinstancechapterexpanded_1 ON DocumentInstanceChapter.PK_DocumentInstanceChapter = documentinstancechapterexpanded_1.FK_DocumentInstanceChapter
INNER JOIN (
      select d.*
            , min(d.IsLocked) over(partition by d.FK_DocumentInstanceChapterExpanded) isLockedMin
            , max(d.IsLocked) over(partition by d.FK_DocumentInstanceChapterExpanded) isLockedMax
      from DocumentInstanceChapterExpandedItem d
      ) AS dicei ON DocumentInstanceChapterExpanded.PK_DocumentInstanceChapterExpanded = dicei.FK_DocumentInstanceChapterExpanded
WHERE (DocumentInstance.PK_DocumentInstance = 455)
AND documentinstancechapterexpanded_1.PK_DocumentInstanceChapterExpanded = 50730

edit, due to the bit column, case expressions were needed:
            , min(case when d.IsLocked = 1 then 1 else 0 end) over(partition by d.FK_DocumentInstanceChapterExpanded) isLockedMin
            , max(case when d.IsLocked = 1 then 1 else 0 end) over(partition by d.FK_DocumentInstanceChapterExpanded) isLockedMax

Comment: Thank you i have posted the result above . I didnt know how to add it in the comment section.
Comment: I have banged my head for 8 hours to get this sorted out using group by , cross join. I cannot thank you enough. All the best.
Comment: I hear you, and I know what it is like, so it's a pure pleasure to assist :) cheers.

Count Frequency based on Bit Flag


How to interpret an event of a Markov chain?

Question: Suppose $\{X_n\}_{n=0}^{\infty}$  is a Markov chain with state space $S = \{0,1,2,...,N\}$ with
$$
P(X_1=0|X_0=0)=1
\\
P(X_1=N|X_0=N)=1
$$ then why the following result is true?
$$
\{X_n=N\}\subset{\{X_{n+1}=N\}}
$$
In fact, I am having hard time to understand how does the event $\{X_n=N\}$ look like. What are the elements of the event $\{X_n=N\}$?
Answer: What this result says is that if $X_n = N$ then $X_{n+1} = N$, which is true since $P(X_{n+1} = N | X_n = N) = 1$, as you state.
Regarding your second question, the event $X_n = N$ consists of all infinite sequences $X_0,X_1,X_2,\ldots$ satisfying $X_n = N$.
Comment: "Regarding your second question, the event" $\{X_n=N\}$ consists of all the outcomes $\omega$ in the sample space $\Omega$ such that $X_n(\omega)=N$, in short, $$\{X_n=N\}=\{\omega\in\Omega\mid X_n(\omega)=N\}.$$


Quando é recomendado usar índices decrescentes?

Question: Por default, os bancos de dados relacionais criam índices usando estruturas de árvores binárias ordenadas de forma crescente. Porém existe a possibilidade de criá-lo de forma decrescente também.
Minha dúvida é se (e quando) é recomendado usá-lo. Por exemplo:
SELECT nome
FROM pessoa
WHERE data_cadastro >= '2014-01-01'
ORDER BY data_cadastro DESC

No SQL acima, considerando o WHERE e ORDER BY, um índice decrescente na coluna data_cadastro melhoraria o desempenho?
Comment: Por que tentaram fechar essa questão ?
Comment: @gmsantos O motivo escolhido foi "Baseada em Opiniões"
Comment: Bem coloquei uma resposta tentando explicar o básico de como a ordenação vai afetar selects e inserts. Acredito que isso esteja dentro do escopo da pergunta do OP e não é baseada em "opnião pessoal" mas em fatos de como funcionam os índices
Comment: Exato, @jean. Acredito que tenham se equivocado ao votar para fechar.
Answer: Imagine um índice em uma coluna de uma tabela agrupada:
CREATE TABLE mytable (
   pk INT NOT NULL PRIMARY KEY,
   col1 INT NOT NULL
)
CREATE INDEX ix_mytable_col1 ON mytable (col1)

O índice em col1 mantém valores de col1 ordenados junto com as referências das linhas.
Uma vez que a tabela é agrupada, as referências às linhas são realmente os valores da pk. Eles também são ordenados dentro de cada valor de col1.
Isto significa que os índice estão ordenados em (col1, pk), e esta consulta:
SELECT  col1, pk
FROM    mytable
ORDER BY
    col1, pk

Não precisa de ordenação!
Se criarmos o índice da seguinte forma:
CREATE INDEX ix_mytable_col1_desc ON mytable (col1 DESC)

em seguida, os valores de col1 serão classificados descendente, mas os valores de pk dentro de cada valor de col1 serão classificados ascendente.
Isto significa que a seguinte consulta:
SELECT  col1, pk
FROM    mytable
ORDER BY
    col1, pk DESC

Pode ser servido por ix_mytable_col1_desc mas não por ix_mytable_col1.
Comment: "Não precisa de ordenação" pode levar incorretamente a presunção de que fazer um select sem order by vai retornar os valores ordenados pelo índice oquê não é garantido! Na verdade a engine vai ainda tentar ordenar de acordo com a definição do order by. Apenas vai ter bem menos trabalho ao faze-lo
Comment: Sim, sim! Mas isso já vai justamente dar menos trabalho. Dificilmente você faz um select sem order by hoje se for para exibição em tela...a não ser que utilizem frameworks que já ordenem automaticamente
Answer: Depende da sua necessidade.
Por default os índices são criados na ordem crescente porque, em geral, os valores (normalmente ids) são gerados de forma crescente. Desta forma os novos (maiores) valores vão para o fim da "lista". Isso diminui a chance de fragmentação do índice.
Exemplo:
Suponha que vc tem uma tabela onde o Id é autoident começando em 1 e acrescentando +1 a cada novo registro. Você define essa coluna como PK clustered mas muda a ordem do índice para decrescente.
Isso vai forçar page splits uma vez que cada novo registro vai forçar a reordenação da tabela.
Um cenário plausível para usar a ordenação decrescente poderia ser onde você faz poucos inserts mas costuma fazer muitos selects sobre os valores mais novos
Exemplo: Você tem um registro de reuniões em que vc compareceu e cria um índice ordenado pela data. Eventualmente uma nova reunião é inserida e você costuma apenas usar um select para retornar as reuniões da última semana.
Como sempre em SQL tudo depende. Na dúvida faça um acid teste. Experimente operações de select, insert, delete, update sobre a tabela em questão usando a ordenação das duas formas e tente medir as difereças de performance. Esse é realmente o único jeito de descobrir como melhorar a performance de um índice


Facebook Autopost. Why I still receive download library message?

Question: I want to use Facebook Autopost. I have downloaded the facebok-php-sdk library and I have copied it to sites/all/libraries, but in status report I still receive this message. What should i do?
Answer: Please make sure that the facebook.php file is found at sites/all/libraries/facebook-php-sdk/src/facebook.php.


Retornando get_status_display no json (Django)

Question: Eu criei uma Issue.
https://github.com/rg3915/orcamentos/issues/53
Eu fiz um gráfico usando Morris JS
https://github.com/rg3915/orcamentos/blob/master/img/graphic.png

Pergunta: como eu faço para retornar get_status_display no json?
import json
from django.db.models import Count
from django.core.serializers.json import DjangoJSONEncoder
from django.http import HttpResponse
from .models import Proposal

def proposal_per_status_json(request):
    ''' Quantidade de orçamentos por status '''
    data = Proposal.objects.values('status')\
        .annotate(value=Count('status'))\
        .order_by('status').values('status', 'value')
    '''
    Precisa reescrever o dicionário com os campos do gráfico,
    que são: 'label' e 'value'.
    '''
    data = [{'label': x['status'], 'value':x['value']} for x in data]
    s = json.dumps(list(data), cls=DjangoJSONEncoder)
    return HttpResponse(s)

http://localhost:8000/proposal/proposal/proposal_per_status_json/
[{"label": "a", "value": 11}, {"label": "c", "value": 9}, {"label": "co", "value": 28}, {"label": "elab", "value": 9}, {"label": "p", "value": 14}]

Mas eu queria
[{"label": "aprovado", "value": 11}, {"label": "cancelado", "value": 9}, {"label": "concluído", "value": 28}, {"label": "em elaboração", "value": 9}, {"label": "pendente", "value": 14}]

STATUS_FILTER = (
    ('c', 'cancelado'),
    ('elab', 'em elaboração'),
    ('p', 'pendente'),
    ('co', 'concluido'),
    ('a', 'aprovado')
)

Comment: O que vc quer não é um JSON válido. JSONs são basicamente objetos em JavaScript, e o que vc postou são dois valores, uma lista e uma tupla. Você pode converter isso num dict, mas não é ideal incluir dados que se repetem em requisições AJAX por conta do overhead. Sugiro incluir os status na renderização do template.
Answer: from orcamentos.utils.lists import STATUS_LIST
p=Proposal.objects.values('status')\
.annotate(value=Count('status'))\
.order_by('status').values('status', 'value')
lista=[]
for item in p:
    for choice in STATUS_LIST:
        if choice[0] == item['status']:
            lista.append({'label': choice[1], 'value': item['value']})

return lista

Comment: Outra solução um pouco mais performática `lista = [{'label': STATUS_DICT[item['status']], 'value': item['value']} for item in data]`.


How to check that the current process is running as Windows Service using WinAPI functions?

Question: I have a program that can be run as a simple console application or can be registered as Windows Service. I want to detect in main() function the current running context:
#include <windows.h>

BOOL IsWindowsService()
{
    ???
}

int main(int argc, char** argv)
{
    if (IsWindowsService())
    {
        // Running as Windows Service...
        RunService();
        return;
    }

    // Running as console application...
    return 0;
}

The main use-case is to have a single exe file that can be installed and run as a Windows Service with '--install' and '--start' arguments or executed without any parameters in console mode (e.g. from VS debugger).
Can you help me with a possible implementation of IsWindowsService() function?
Comment: when you register your application as service - set some commandline, known to you, and then check command line - based on this you can understand are you exec via service key with this command line or no. best of all use symbols like `<`, `>`, `|` which can not be in command line if your application exe via some filesystem shell
Comment: Now that you've added the mention of `--start` parameter, you don't need an `IsWindowsService()` function at all, you just need to inspect the parameters.
Comment: I need because `--start` parameter check with `StartService()` is used only outside the `IsWindowsService()` scope!
Comment: Your parameters are right there -- `argc` and `argv` -- so just move your parameter processing before you need to make the decision.
Answer: int __stdcall wWinMain(HINSTANCE, HINSTANCE, LPWSTR, int)
    {
    SERVICE_TABLE_ENTRY ServiceTable[] =
    {
        { SERVICE_NAME,(LPSERVICE_MAIN_FUNCTION)ServiceMain },
    { NULL,NULL }
    };
    if (StartServiceCtrlDispatcher(ServiceTable))
        //service
    else app; // last error ERROR_FAILED_SERVICE_CONTROLLER_CONNECT
}

VOID WINAPI ServiceMain(DWORD argc, LPTSTR *argv)
{...}

Documentation https://learn.microsoft.com/en-us/windows/desktop/api/winsvc/nf-winsvc-startservicectrldispatchera
Answer: It seems that I found an elegant solution for the problem which does not require providing special command line argument to handle (solution provided by @RbMn):
BOOL IsWindowsService()
{
    DWORD sessionId = 0;
    ProcessIdToSessionId(GetCurrentProcessId(), &sessionId);
    return !sessionId;
}

This solution works because all Windows Services run in Session 0 along with applications.
Comment: Also consider that Michael's method is "perfect" in the sense that it adds no new code at all to the service path.  The service path *must* call `StartServiceCtrlDispatcher()`.  So you get its return value for free.
Comment: This does not tell you that your application is a service.  It could be spawned from a service.  Can you clarify your question to explain whether "spawned from a service" should or should not count?
Comment: My use case is to have a single exe file that can be installed and run as a Windows Service with '--install' and '--start' arguments or executed without any parameters in console mode (e.g. from VS debugger).
Comment: I understand that.  Both your method and Michael's will give the correct answer in those two cases.  They will give a different answer in the case your exe file is spawned from another service.. What answer do you want in that case?
Answer: You can use system() function. It will execute any command that can run on command prompt. Use it like this:
system("tasklist > tasks.txt");

This will store all running tasks to tasks.txt. Then you can check is your program running or not by searching for it in the file.
for more information about tasklist, run command prompt, execute this:
tasklist /?


How do I capture the current command and send it into a script as an argument?

Question: I hope the title of this question isn't too confusing.
What I want to do is send myself an e-mail when a specified command has finished running in the shell. For this purpose, I wrote a simple script that takes an argument and sends me an e-mail with the argument as the messages text.  The idea is to be able to execute a command that I know will take a long time in the following manner:
./commandThatTakesALongTime; ./emailingScript <some argument>

The obvious answer here is to just write the name of the command again, and pass it in as a string but often I'll have commands with lots of arguments, and so I'd prefer it to automatically grab what was executed.
I've tried using various combinations of !!:p, but that doesn't appear to be working. Any tips?
ETA: I'm looking for something that I can pass as  which will basically just print "./commandThatTakesALongTime"--does such a thing exist? The reason I'm doing it this way is because I need my environment to be preserved as it is after the command is executed.
Answer: Write a script like this:
#!/bin/bash

if "$@" ; then
    echo "$@" | mail -s 'command complete' firstname.lastname@example.com
else
    echo "Command failed!"
fi

Save this as exec_and_mail and make it executable.
You run it as exec_and_mail some_command -with arguments --passed --to it.
Comment: You cannot pass environment variables from a child process to the parent.  The child inherits the parent environment and can modify it, but it's not going to affect the parent environment in any way.  There are workaround to this and they amount to passing a script to the parent which sets the environment variables.
Comment: In other words: nothing that a command does to its environment will affect the environment of the process (or shell) that executed the command.  So your environment will not be modified.
Comment: There's no way for a script to get information from the rest of the command line. That's why this script takes the command line as an argument, and it executes the command for you. It will inherit your environment variables.
Comment: Question, which should've been stated in the original problem definition--will this preserve my environment? Some of the programs that I have that are longer-running are changing environment variables and those need to be preserved. Thanks.
Comment: Which I think brings me back to where I started--sequentially executing two commands and just breaking them up with the semicolon. The issue is just what do I send to my script as an argument?
Comment: The problem is that I need to be able to inherit environment variables from the commands that I'm running.
Comment: You could *source* the posted script: `source exec_and_mail some_command -with arguments --passed --to it`, but you still have to make sure the given command is just a simple command with arguments, no pipelines or lists.
Comment: The command you execute will not modify the environment of the process it was started from.  If you execute *any* command, your environment will be unchanged after that command finishes.  It simply cannot change your environment (only its own).  If you source a script, then the script runs in the same process as the shell, and thus it can change the environment (but none of the commands executed in the script can).
Comment: @smintitule: Is `./commandThatTakesALongTime` actually `source ./commandThatTakesALongTime` or something similar? If not, it can't modify the shell's environment anyway, which is why everyone is confused by your requirement.


Javascript program to print all stars pattern in single code with 2 for loops

Question: I need Javascript code to print all star patterns using a single program with only 2 for loops. I tried the following code but it prints only diamond shape.
var spaces = " ";
var rows = "* ";
while(rows.length < 200) {
    spaces += spaces; // doubles length each time
    rows += rows; // ditto
}

function diamond(n) {
    n = parseInt(n, 10);
    var i, s;
    // top: 1 to n
    console.log("
");
    for(i = 1; i <= n; ++i) {
        // write n-i spaces:
        console.log(spaces.substring(0,n-i));
        // then write i asterisk+space sets:
        console.log( rows.substring(0,i+i) + "\n");
    }
    // bottom: n-1 down to 1
    for(i = n-1; i >= 1; --i) {
        // write n-i spaces:
        console.log( spaces.substring(0,n-i) );
        // then write i asterisk+space sets:
        console.log( rows.substring(0,i+i) + "\n" );
    }
    console.log("
");
}
diamond(9);

Answer: You can try
let star = "";
for(let i=1; i<=50; i++) {

  for(let j=1; j<=i; j++) {
    star += "*";
  }
  star += "\n";
}
console.log(star);

Answer: Well, there are many star patterns, you didn't specify which ones you're interested in.
Anyway, if you can read and translate simple C code to Javascript, here is a link to 9 star pattern you could try
http://cbasicprogram.blogspot.it/2012/03/star-patterns.html
Star pattern algorithms are generally very simple to understand in every language since they are used as beginner exercises. If you don't find anything JS related, try and search in another language.
Answer: You can also use the switch case to print out the star patterns:
for (let x = 1; x <= 9; x++) {
  switch (x) {
    case 1:
      console.log("*");
      break;
    case 2:
      console.log("**");
      break;
    case 3:
      console.log("***");
      break;
    case 4:
      console.log("****");
      break;
    case 5:
      console.log("*****");
      break;
    case 6:
      console.log("******");
      break;
    case 7:
      console.log("*******");
      break;
    case 8:
      console.log("********");
      break;
    case 9:
      console.log("*********");
      break;
  }
}


Unable to Inject Dependency ngMaterial

Question: I am looking to develop an application that uses both dirPagination and AngularJS material. However, I am unable to inject the ngMaterial dependency into my application. The angularUtils.directives.dirPagination dependency works fine, but as soon as I add ngMaterial, the AngularJS application crashes.
Here is a Plunker with an example (https://plnkr.co/edit/7N7i9TnMc77Nz6xlNhuk?p=preview). In app.js, which is where I instantiate the module, both dependencies are there. If the line reads:
angular.module('myApp', ['angularUtils.directives.dirPagination', 'ngMaterial']);

Then AngularJS crashes and the page reads {{hello}}. However, since in the controller, I have set $scope.hello to "Hello Plunker!", if the line reads:
angular.module('myApp', ['angularUtils.directives.dirPagination']);

Then the page displays "Hello Plunker!".
What am I doing wrong?
Thanks for your help!
Answer:
You need to include angular.js before any other script that is going to use angular. Here you add script.js before angular.js
You also need to use the same versions of angular modules angular-animate, angular-aria, angular-messages as that of angular.js version
Here you used 1.6.4 version of angular.js

You can check for the modifications I made to your plnkr https://plnkr.co/edit/En0YaiaiqD1MPPOydAf8?p=preview
Also there were errors for cross domain request for bootstrap.min.css which can be easily fixed by using

https://

cdn
Answer: This is a working demo, was having version issue and also order of declaring JS file.

<!DOCTYPE html>

    <link rel="stylesheet" href="https://ajax.googleapis.com/ajax/libs/angular_material/1.0.0/angular-material.min.css">
    <link rel="stylesheet" href="https://www.w3schools.com/w3css/4/w3.css">
    <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css">

{{hello}}

        <md-toolbar class="md-warn">

HTML 5

      </md-toolbar>

Answer: You are missing the script for material.css, and the order is wrong.

  <link rel="stylesheet" href="//rawgit.com/angular/bower-material/master/angular-material.css" />

WORKING DEMO
Answer: I'll just add that angular-material.js requires angular-animate.js and angular-aria.js, and the latter two should go before angular-material.js. angular-messages.js doesn't seem to be required.

Unable to Inject Dependency ngMaterial


How can I mitigate humidity causing me to stop short on the approach?

Question: This past weekend, I was throwing a couple of games at a new alley and I found that I was consistently stopping short. To clarify, each time I released my ball, my lead foot wouldn't slide instead it would stop at least a few inches short of where I had hoped it would go to allow for a smooth release.
My shoes were clean, however, it was raining outside and I think some of that humidity was out-competing the house's air conditioning. I tried brushing my shoes just to be sure, but it didn't really help. I also tried adjusting my starting position to make the release closer to the line, however, it didn't really change the fact that my foot was sticking was impeding a smooth release.
Is there anything else that can be done when humidity in the building is making the approach feel sticky?
Answer: While humidity may or may not have been the cause that's not strictly speaking relevant since the problem is the difference in friction on the approach to what you're used to. I've known this to vary wildly between different centres!
And I'm not alone in this - which is why shoe manufacturers offer interchangeable soles to suit (e.g. Linds' VHS system)
What do you do if you don't have such shoes though? Well there's no great options in my experience - something like Brunswick's Smooth slide is probably your best bet or a dusting from a puffball in a pinch.
Comment: @Pyrotechnical I've never known anyone to have a problem with it - you're applying to to your shoes rather than the approach so unless you're applying way, *way* too much it's not going to really leave any behind to impact others
Comment: Is using something like that permissible? I don't want to create a slip hazard for other bowlers.


Convergence in probability over compact set

Question: Let $(\Omega,\mathcal{F},P)$ be a probability space. Suppose $(X_n)\subseteq (\mathbb{R}^k)^{\Omega}$ is a sequence of random vectors converging in probability to the vector $c\in \mathbb{R}^k$. Let $(\Psi_n)$ be a sequence of functions $\Psi_n:\mathbb{R}^k\times \Omega\to \mathbb{R}$, such that for all $n$ and all $x\in \mathbb{R}^k$, $\Psi_n(x,\cdot)$ is measurable. Consider also a continuous function $\Psi:K\to \mathbb{R}$ where $K$ is a compact subset of $\mathbb{R}^k$ containing $c$. Do we have that:
$$
\forall \varepsilon>0,\ \lim\limits_nP(\sup\limits_{x\in K}|\Psi_n(x,\cdot)-\Psi(x)|>\varepsilon)=0\Rightarrow \forall \varepsilon>0,\ \lim\limits_nP(|\Psi_n(X_n,\cdot)-\Psi(c)|>\varepsilon)=0\ ?
$$
Comment: I think you might need a condition that $c$ is interior to $K$. It seems the statement is incorrect e.g. if $K=\{c\}$.
Comment: Indeed, that's the problem I had and it is the reason for the question mark up there xD
Comment: @Arizabalaga Does your question in anyway relate to my post [(Click here)](https://math.meta.stackexchange.com/a/4726/125918)?
Comment: I could not say, I will think more about it
Answer: In retrospect, as pointed in the comment section, the hypothesis should allow $c$ to be an interior point $K$.
In that case, the answer is affirmative.

Let $\tilde{\Psi}$ be any extension of $\Psi$ to an continuous function on $\mathbb{R}^k$.
Because $c$ is an interior point of $K$ hence there is a positive number $r>0$ such that $$B_r(c) \subset K$$.
So if $|X_n-c|<r$, we have
$$\begin{align}|\Psi_n(X_n,\cdot)-\Psi(c)| &\le |\Psi_n(X_n,\cdot)-\Psi(X_n)|+|\Psi(X_n) - \Psi(c)| \\ & \le \sup_{x \in K} |\Psi_n(x,\cdot)-\Psi(x)|+|\Psi(X_n) - \Psi(c)|
\\ &= \sup_{x \in K} |\Psi_n(x,\cdot)-\Psi(x)|+|\tilde{\Psi}(X_n) - \tilde{\Psi}(c)| \end{align}$$
Thus if $\epsilon< |\Psi_n(X_n,\cdot)-\Psi(c)|$ and $|X_n-c|<r$, we have either $$\epsilon/2 < \sup_{x \in K} |\Psi_n(x,\cdot)-\Psi(x)| $$ or $$\epsilon/2 <|\tilde{\Psi}(X_n) - \tilde{\Psi}|(c)|  $$
So :
$$\begin{align}
\mathbb{P}(\epsilon< |\Psi_n(X_n,\cdot)-\Psi(c)|) &\le \mathbb{P}( |X_n-c| \ge r)+ \mathbb{P} \left( \epsilon/2 < \sup_{x \in K} |\Psi_n(x,\cdot)-\Psi(x)|\right)\\ &+ \mathbb{P} \left( \epsilon/2 <|\tilde{\Psi}(X_n) - \tilde{\Psi}(c)|\right)
\end{align}
$$
Hence the conclusion.


Spring boot, runnable jar can't load package-info.class

Question: We use Spring boot with hibernate database mapping.
The entities contains JSON columns mapped as a customized types defined using package-info.java file.
When we run the spring-project from Eclipse IDE everything is ok and we can call our web services.
When we generate an executable jar and we try to call our web services the following error is raised :
mai 04, 2017 1:35:00 PM org.apache.catalina.core.StandardWrapperValve invoke
GRAVE: Servlet.service() for servlet [dispatcherServlet] in context with path [] threw exception [Request processing failed; nested exception is java.lang.RuntimeException: Unable to execute job Test] with root cause
java.lang.NoClassDefFoundError: BOOT-INF/classes/com/test/package-info (wrong name: com/test/package-info)
    at java.lang.ClassLoader.defineClass1(Native Method)

The file package-info.class is into the jar BOOT-INF/classes/com/test/package-info
What can be wrong ?
Thanks for any help
Comment: What's trying to load package info? It's using the wrong name
Comment: Its contains annotations for a user type definition used for hibernate JSON column mapping. The content was as :
@org.hibernate.annotations.TypeDef(name = "UserJsonType", typeClass = StringJsonUserType.class)

package com.bean;

import com.bean.type.StringJsonUserType; Actually we resolved the problem by replacing the definition of the type in all classes thus we delete the package-info.java. But is there a way to used it ?
Comment: I'm stuck in the same situation. I created a JAXB reader within a spring boot/spring batch application. Inside Eclipse everithing it's OK. When I build with Maven and then run it, I get  a `java.lang.NoClassDefFoundError: BOOT-INF/classes...`. Maybe the problem is the way the `spring-boot-maven-plugin` packages the compiled classes. I'm trying to investigate further...
Comment: Same problem, with spring-boot 1.5.x, this all worked fine previously. Can anyone at spring assist?
Comment: For anyone else in the spring world, here is a sample project re-producing the issue: https://github.com/nfedyk/spring-boot-jpa-issue-01
Answer: I solved this issue by disabling package scan and autodetection of classed for Hibernate
<persistence-unit name="sqlProvider" transaction-type="RESOURCE_LOCAL">
    <provider>org.hibernate.jpa.HibernatePersistenceProvider</provider>
    <class>com.example.package.dao</class>

    .........
    <properties>
        <property name="exclude-unlisted-classes" value="true"/>
        <property name="hibernate.archive.autodetection" value="hbm" />
        .........
    </properties>
    .........
</persistence-unit>

Answer: I didn't want to disable scanning as manually adding all classes to persistence.xml wasn't an option. Since we do not actually use package level annotations for hibernate in our project, I created this little abomination:
package com.example;

import org.hibernate.boot.archive.scan.internal.ScanResultImpl;
import org.hibernate.boot.archive.scan.internal.StandardScanner;
import org.hibernate.boot.archive.scan.spi.ScanEnvironment;
import org.hibernate.boot.archive.scan.spi.ScanOptions;
import org.hibernate.boot.archive.scan.spi.ScanParameters;
import org.hibernate.boot.archive.scan.spi.ScanResult;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.Collections;

public class HibernateHackScanner extends StandardScanner {

    private static final Logger log = LoggerFactory.getLogger(HibernateHackScanner.class);

    @Override
    public ScanResult scan(ScanEnvironment environment, ScanOptions options, ScanParameters parameters) {
        log.info("Hack-Scanner is active, annotated packages will not be found by this scanner.");
        ScanResult scan = super.scan(environment, options, parameters);
        return new ScanResultImpl(Collections.emptySet(), scan.getLocatedClasses(), scan.getLocatedMappingFiles());
    }
}

Then I enabled this custom scanner in persistence.xml:
<property name="hibernate.archive.scanner" value="com.example.HibernateHackScanner"/>

This scanner uses the standard scanner under the hood and simply discards all annotated packages which have boot_inf.classes etc. prepended to their package. If you actually need package level annotations you would need to get a bit more sophisticated than this crutch, though. But this works for me ¯\_(ツ)_/¯
Answer: Nestor Fedyk solution helped me in resolving the issue.
please find the code below, i have added the solution to my hibernate config file
"exclude-unlisted-classes"
"hibernate.archive.autodetection" properties added
  <bean id="entityManagerFactory" class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">
    <property name="dataSource" ref="rcsDataSource"/>
    <property name="persistenceUnitName" value="corePersistenceUnit"/>
    <property name="jpaVendorAdapter" ref="hibernateJpaVendorAdapter"/>
    <property name="jpaProperties">
        <props>
            <prop key="hibernate.query.factory_class">org.hibernate.hql.internal.classic.ClassicQueryTranslatorFactory</prop>
            <prop key="hibernate.cache.use_second_level_cache">false</prop>
            <prop key="hibernate.cache.use_query_cache">false</prop>
            <prop key="hibernate.cache.region.factory_class">xxxx.xxxxxxxx.xxxx</prop>
            <prop key="hibernate.cache.provider_class">xxx.xxxxxxxx.xxxx</prop>
            <prop key="hibernate.cache.use_structured_entries">false</prop>
            <prop key="hibernate.generate_statistics">true</prop>
            <prop key="hibernate.default_batch_fetch_size">250</prop>
            <prop key="hibernate.max_fetch_depth">5</prop>
            <prop key="hibernate.jdbc.fetch_size">300</prop>
            <prop key="exclude-unlisted-classes">true</prop>
            <prop key="hibernate.archive.autodetection">"hbm"</prop>
        </props>
    </property>
    <property name="jpaDialect">
        <bean class="org.springframework.orm.jpa.vendor.HibernateJpaDialect" />
    </property>
</bean>

I hope this helps
Answer: I use cxf-codegen-plugin to generate entites. In my case excluding package-info class solved the problem. I deleted package-info.class from project file, add extraargs to pom file like:
 <plugin>
                <groupId>org.apache.cxf</groupId>
                <artifactId>cxf-codegen-plugin</artifactId>
                <version>${cxf.version}</version>

                <executions>
                          <execution>
                            <id>mvn s</id>
                            <phase>generate-sources</phase>
                            <configuration>
                                <sourceRoot>${project.build.directory}/generated/cxf</sourceRoot>
                                <sourceRoot>${basedir}/src/main/java</sourceRoot>
                                <wsdlOptions>
                                    <wsdlOption>
                                        <wsdl>${basedir}/src/main/resources/wsdl/YOURWSDL.wsdl</wsdl>
                                        <wsdlLocation>classpath:wsdl/YOURWSDL.wsdl</wsdlLocation>

                                        <bindingFiles>
                                            <bindingFile>${basedir}/src/main/resources/wsdl/bindings.xml</bindingFile>
                                        </bindingFiles>

                                    </wsdlOption>

                                    <wsdlOption>
                                        <wsdl>${basedir}/src/main/resources/wsdl/YOURWSDL.wsdl</wsdl>

                                    </wsdlOption>
                                </wsdlOptions>

                                <defaultOptions>
                                    <extraargs>
                                        <extraarg>-xjc-npa</extraarg>
                                    </extraargs>
                                </defaultOptions>

                            </configuration>
                            <goals>
                                <goal>wsdl2java</goal>
                            </goals>
                        </execution>
                </executions>
            </plugin>

and package file: mvn clean install spring-boot:repackage -DskipTests. Now it works fine.
Answer: I managed to make it work with a modification of Jan Thomä's solution:
package com.example;

import org.hibernate.boot.archive.scan.internal.PackageDescriptorImpl;
import org.hibernate.boot.archive.scan.internal.ScanResultImpl;
import org.hibernate.boot.archive.scan.internal.StandardScanner;
import org.hibernate.boot.archive.scan.spi.*;
import org.hibernate.boot.archive.spi.ArchiveDescriptorFactory;

import java.util.Set;
import java.util.stream.Collectors;

public class CustomHibernateScanner extends StandardScanner {

    private static final String SPRING_BOOT_JAR_PREFIX = "BOOT-INF.classes.";

    public CustomHibernateScanner() {
    }

    public CustomHibernateScanner(ArchiveDescriptorFactory value) {
        super(value);
    }

    @Override
    public ScanResult scan(ScanEnvironment environment, ScanOptions options, ScanParameters parameters) {
        ScanResult result = super.scan(environment, options, parameters);
        Set<PackageDescriptor> pkgDesc = result.getLocatedPackages().stream()
                .map(this::fixPackageDescriptor)
                .collect(Collectors.toSet());
        return new ScanResultImpl(pkgDesc,
                result.getLocatedClasses(),
                result.getLocatedMappingFiles());
    }

    private PackageDescriptor fixPackageDescriptor(PackageDescriptor pd) {
        if (pd.getName().startsWith(SPRING_BOOT_JAR_PREFIX)) {
            return new PackageDescriptorImpl(pd.getName().substring(SPRING_BOOT_JAR_PREFIX.length()), pd.getStreamAccess());
        }
        return pd;
    }

}

It is added to persistence.xml as in the original answer. It basically removes the prefix in package descriptor name that is causing the exception.
This way, it works and no package scanning needs to be disabled.
Answer: You can extract the package containing the JAXB generated classes (that is the package containing the package-info class) in an external jar. Move to the new project the JAXB related resources, too (e.g., the XSD file).
Now you can set such a jar as a dependency of the project producing the exacutable jar.
This way, my Spring Batch/Spring Boot project works when I run it from command line. I'm aware that it's not an optimal solution but, in my case, it works.
Comment: When did this become a requirement for JAXB classes to be separated out into separate projects? They can no longer live in the source tree of your code? I mean our JAXB classes are a core part of our spring-boot app itself.... not a separate library.
Comment: Please, ask spring boot guys, not me.


Sorting an array in a foreach loop in php

Question: I am looking at how to sort an array within a foreach loop to place my featured jobs to the top of the list.
The key and values are 'Featured Job' => 'Yes' or 'Featured Job' => 'No'
I am just checking to see if the key isset and then outputting a string saying 'Featured Job' - that part was easy. I am just unable to sort them to place the featured jobs at the top.
Here is my code, any hints or help would be appreciated:
    if( isset($v->customLovs) && !empty($v->customLovs->customLov) ) {
        $lovs = $v->customLovs->customLov;

      if( isset($lovs->label) )
        $lovs = array( $lovs );

      foreach( $lovs as $lov ) {
        switch( $lov->label ) {
          case "Position":
            $position = $lov->criteria->criterion->label;
            break;
          case "Town or City":
            $townOrCity = $lov->criteria->criterion->label;
            break;
          case "Featured Job":
            $fjob = $lov->criteria->criterion->label;
            break;
        }
      }
    }

And here is the output:

<?php echo $position;?>

<?php if ( isset($fjob) ) : ?>Featured Job<?php endif; ?>
<?php echo $townOrCity;?>

My feeble attempt to cure this was like so:

$lovs = usort($lovs);

I can only assume that I need to target the $fjob somehow?
Comment: Do a `usort` before looping?
Comment: @JonStirling - this is something I tried on ```$lovs``` but it seemingly had zero effect. Unless I was putting it in the wrong place?
Comment: Maybe? I don't know, I wasn't there ;)
Comment: @JonStirling - haha I cannot argue with that! could you point me in the right direction?
Comment: http://php.net/usort or put your sorting attempt in your question so we can have a look.
Comment: @JonStirling - see my updated answer - I am just looking at the link provided
Comment: Yep,your attempt is incomplete, the link might need a couple of takes, but everything you need is in there.
Comment: @JonStirling - the issue I am encountering is that before the loop the variable doesn't exist yet so I'm not able to target it...Unless I am missing the point?
Answer: You can look up php documentation on sorting arrays. you can create a date key and sort by the date.
 http://php.net/manual/en/array.sorting.php
Comment: you can create a variable that holds your featured jobs, then write an if statement asking- if the featured job is in the array... sort by the featured job
Comment: Would it be possible to perhaps show me an example because that is exactly where I am struggling because the variable is yet to exist - is it possible in the last case?


Cannot send drupal_http_request authorization header

Question: I'm trying to post a request using drupal_http_request, but my headers are causing authorization errors.
This is my request:
$headers =  array('Authorization'=>'Bearer [my token here]', 'Content-Type'=>'application/json' );
$url = "https://api.ionic.io/push/notifications";
$message= new stdClass();
$message->message='That works';
$message->title='titleofmessage';
$data = array('tokens' => array('DEV-f765ac70-1bcb-4e0f-8bfd-adfd9612f185'), 'profile'=>'fake_push_profile', 'notification'=>$message);
$result=drupal_http_request($url, $headers, 'POST', json_encode($data));

In cURL it works fine, but I want to use drupal_http_request:
curl -X POST -H "Content-Type: application/json" -H "Authorization: Bearer [my token here]" -d '{"tokens": ["DEV-f765ac70-1bcb-4e0f-8bfd-adfd9612f185"],"profile": "fake_push_profile","notification": {"message": "That works", "title": "titleofmessage"}}' "https://api.ionic.io/push/notifications"

The error message I get is 'Authorization header is missing' so something seems to be happening to that header.
Any help much appreciated!
Answer: You have the second param to drupal_http_request wrong; it should be an array of options, not an array of headers. Headers is just one of those options.
To fix:
$result = drupal_http_request($url, array('headers' => $headers), 'POST', json_encode($data));

Comment: Thanks Clive. You are right, but it still didn't work for me. That made me recheck the documentation for drupal_http_request and it seems i've been using the drupal 6 notation. My request should have been

     $options=array('headers'=>$headers, 'data'=>json_encode($data), 'method'=>'POST');

 $result=drupal_http_request($url, $options);
Answer: While Clive was right for Drupal 6, I am using Drupal 7. I've marked his answer as correct, but the code I ended up using was:
$headers =  array('Authorization'=>'Bearer [my token here]', 'Content-Type'=>'application/json' );
$url = "https://api.ionic.io/push/notifications";
$message= new stdClass();
$message->message='That works';
$message->title='titleofmessage';
$data = array('tokens' => array('[device token]'), 'profile'=>'fake_push_profile', 'notification'=>$message);

$options=array('headers'=>$headers, 'data'=>json_encode($data), 'method'=>'POST');

$result=drupal_http_request($url, $options);


Crond is running twice with CentOS

Question: I have the following issue that all of my cronjobs are running twice.
When I do:
ps aux | grep cron

I see the following:
root      1379  0.0  0.1 117296  1224 ?        Ss   Aug26   0:00 crond
root     17177  0.0  0.0 103248   860 pts/0    S+   10:42   0:00 grep cron

Two instances. The last one recreates each minute, so you can see time is currently 10:42 am over here. Each minute the instances gets killed and a new one starts with new pid.
Is it here the problem is? How can I solve this?
I am using CentOS 6.
Comment: Where do you see two instances of crond? The output you posted shows only one.
Comment: If you want suppress grep in the output you should do `ps aux | grep cron
| grep -v grep`
Comment: I'm voting to close this question as off-topic because it's basically a misread of the grep output.  http://meta.serverfault.com/a/6160/174813
Answer: when you do ps aux | grep cron you are running two commands - ps aux and grep cron. ps aux lists all processes currently running, and grep cron matches any lines which contain "cron" in them.
Obviously the crond process matches the word cron, but so does the grep cron process you just ran. It's matching itself recursively.

Crond is running twice with CentOS


pandas Series.cumsum() vs pandas.expanding_sum()

Question: assuming I have a pandas Series s, what is the difference between s.cumsum() and pd.expanding_sum(s)? (I guess the answer should be the same also for cummax()/cummin(), and pd.expanding_max()/pd.expanding_min())
The docs say:

Note The output of the rolling_ and expanding_ functions do not
  return a NaN if there are at least min_periods non-null values in the
  current window. This differs from cumsum, cumprod, cummax, and cummin,
  which return NaN in the output wherever a NaN is encountered in the
  input.

Is this the only difference?
(assuming this is the only difference I don't understand why there needs to be 2 different methods defined for this very similar functionality)
Answer: They are basically the same, but you will get NaNs with expanding_sum until you reach the required minimum number of observations.
s = pd.Series([1] * 5)

>>> s.cumsum()
0    1
1    2
2    3
3    4
4    5
dtype: int64

>>> pd.expanding_sum(s, min_periods=3)
0   NaN
1   NaN
2     3
3     4
4     5
dtype: float64

expanding_sum also allows you to pre-conform your time indexed data, apparently based on mean.
s = pd.Series([0, 1] * 5, index=pd.date_range('2015-1-1', periods=10, freq='12H'))

>>> s
2015-01-01 00:00:00    0
2015-01-01 12:00:00    1
2015-01-02 00:00:00    0
2015-01-02 12:00:00    1
2015-01-03 00:00:00    0
2015-01-03 12:00:00    1
2015-01-04 00:00:00    0
2015-01-04 12:00:00    1
2015-01-05 00:00:00    0
2015-01-05 12:00:00    1
Freq: 12H, dtype: int64

>>> pd.expanding_sum(s, min_periods=3, freq='1D')
2015-01-01    NaN
2015-01-02    NaN
2015-01-03    1.5
2015-01-04    2.0
2015-01-05    2.5
Freq: D, dtype: float64

The documentation contains more information on expanding window moment functions.
Regarding the difference in how the two methods treat NaNs, here is an illustrative example:
s = pd.Series([1] * 5)
s.loc[2] = None

>>> s.cumsum()
0     1
1     2
2   NaN
3     3
4     4
dtype: float64

>>> pd.expanding_sum(s)
0    1
1    2
2    2
3    3
4    4
dtype: float64


Finding the projection of y onto the span of two vectors

Question: I was given the following question:

Given $\{u_1,u_2\}$ is an orthogonal set, find the orthogonal projection of $y$ onto Span$\{u_1,u_2\}$.$$y=\left(\begin{matrix}-1\\3\\6\\\end{matrix}\right), u_1=\left(\begin{matrix}-5\\-1\\2\\\end{matrix}\right),u_2=\left(\begin{matrix}1\\-1\\2\\\end{matrix}\right)$$

I know how to find proj$_a\vec{b}$. It is $\frac{a\bullet b}{||a||^2}\vec{a}$. What is throwing me off is the fact that here I'm not looking for the projection of y onto a vector, I'm looking for the projection of y onto the span of two vectors. How do I deal with that?
Comment: You are finding the projection on a plane
Answer: It is the linear combination of those two )i.e., onto the plane spanned by those two orthogonal vectors):
$$Py=\frac{y\cdot u_1}{\left\|u_1\right\|^2}\,u_1+\frac{y\cdot u_2}{\left\|u_2\right\|^2}\,u_2$$
Comment: Thanks! I solved like this and got: $\left(\begin{matrix}-1\\\frac{-9}{5}\\\frac{18}{5}\\\end{matrix}\right)$. The book's answer key says $\left(\begin{matrix}-1\\3\\6\\\end{matrix}\right)$. Am I right? Is the book right? Are the answers the same? What's going on here?


How to clear contents of all the files using find command

Question: Is there an easy step to clear contents of all  ".log" file using find command.
Currently i am using "echo -n > filename.log"
i have tried echo -n > /var/application-logs/*.log but it is not working..
is there a better way to clear contents of multiple files?
Comment: What is your exact find command?
Answer: To clear everything find /var/application-logs -type f -name "*.log" finds, use this:
find /var/application-logs -type f -name "*.log" -exec tee {} \; </dev/null

If your version of find supports it, use + instead of \; to use a single run of tee for all of the files.  Alternately, if a shell glob is sufficient:
tee /var/application-logs/*.log </dev/null

Comment: POSIX stipulates that find supports {} +; I don't know of any that don't.
Comment: @adaptr: I could've sworn I saw one that didn't support `+` recently, but maybe I'm imagining it. You're right, though, it is in [the Posix standard](http://pubs.opengroup.org/onlinepubs/009695399/utilities/find.html).
Comment: Thanks a ton ! This saved me an hour worth of my time.
Answer: If you want to stop your logs from growing, use logrotate. You should not be blindly wiping logs just because they are full. There are good HOWTOs available for many different distros.
Alternatively, consider using a syslog server such as rsyslog or syslog-ng.
Comment: i am using logrotate,,,this is a special case where i want to perform benchmark on application,which i need to monitor logs.So it will be convinient to remove all logs relating to that..
Comment: @hariharan It would be worth updating your original question with this information so that your intent is clear.
Comment: can u please check now...i have changed log location
Answer: I was facing a similar situation where I had to delete Docker Container Logs with ".log" extension using a command or a shell script (it was scenario-specific)
Here's the script
#!/bin/bash

#SHELL SCRIPT TO DELETE THE CONTENT OF THE DOCKER CONTAINER LOG FILES

#Declaring Array
file_list=()

#While loop to read log file name
 while IFS= read -d $'\0' -r file ; do
     file_list=("${file_list[@]}" "$file")
 done < <(find /var/lib/docker/containers/ -type f -name "*.log" -print0)

#Printing log file names
 echo "${file_list[@]}"

#Deleting the content of the log files
 for f in "${file_list[@]}";do
    if [ -f $f ]
    then
      : > "$f"
    fi
 done

Explanation of Bash Elements

file_list=() is an array containing the results of find /var/lib/docker/containers/ -type f -name "*.log"
While loop is used to read the log file names
while IFS= read -d $'\0' -r file ; do
     file_list=("${file_list[@]}" "$file")
 done < <(find /var/lib/docker/containers/ -type f -name "*.log" -print0)

where the find subprocess is used by the while command via <
and IFS= read -d $'\0' -r file is the while condition
which reads one line of input from the find command.
echo "${file_list[@]}" is to print the file name stored in the array.
for f in "${file_list[@]}";do
    if [ -f $f ]
    then
      : > "$f"
    fi
 done

In the above for-(if)-loop snippet, the loop reads each file from the array ${file_list[@]} and the if statement then clears the content of the file using : > "$f"
Comment: This is exactly the type of answer we love to see on Stack Exchange.


Same DBLink name used in Different Schemas of same Database - Invalidates the Procs

Question: I have "PROD-1" db which contains 2 schemas "Schema-1", "Schema-2"
I created the private dblink "DBLINK-1" in both the schemas & they are pointing to different targets.
here is my configuration
DB Name -> Source Schema -> Target DB -> Target Schema  -> Dblink Name
PROD-1    ->   Schema-1   ->    TPRD-1   ->    TSchema-1  ->      DBLINK-1
PROD-1    ->   Schema-2   ->    TPRD-2   ->    TSchema-2   ->     DBLINK-1
I am using this dblink in procedure and deployed in both Schema-1 & Schema-2
when I compile the proc in Schema-1 it is invalidating Schema-2 proc & vice versa.
here is the sample proc
CREATE OR REPLACE procedure test_dblink

is
v_cnt number;
begin
   select count(*) into v_cnt from DUAL@DBLINK-1;

end;
as per my understanding, DBLINK-1 is a private dblink for the Schema-1 & Schema-2; therefore it should not conflict with each other. however, when I executed the procedures at the same time in both schemas, one procedure exectued successfully & other one was waiting for first one to complete then complete.
this is what may be happening

Schema-1 proc started first and Proc status is Valid. Schema-2 proc was waiting
Schema-1 proc completed now. Schema-2 proc came out of wait mode & invalidated the DBLink-1 in Schema-1. therefore Schema-1 proc is now Invalid status
Schema-2 proc run and complete. Schema-2 proc is Valid now

My question is, how can I manage the same DBLink in two different schema of same DB without this conflict?
Appreciate you help
Comment: this is bad practice to name objects the same in different schema's but ... you are right - dblinks are private objects. are you creating the procedures from the user it self ? (i mean , you ran the `create procedure` while logged on as schema-1 ? )
Comment: Hello Haki, thanks for your response. Finally I found the problem by creating the P1 ticket with Oracle. Bug 7395995
Answer: We solved that using Synonyms. Use unique names for your db links. Then create synonyms in each schema for each remote object that you use. This way you can still use identical PL/SQL code in both schemas.


SQL table for Address and Localization

Question: I need to save a list of Places and Persons in a Database including their Addresses and Latitude / Longitude. Sometimes I have an address other times only Latitude / Longitude other times none. So I have:
create table dbo.Persons (
  Id int identity not null primary key clustered (Id),
  AddressId int not null,
  Name nvarchar (100) null,
  Localization geography null
)

create table dbo.Places (
  Id int identity not null primary key clustered (Id),
  AddressId int not null,
  Name nvarchar (100) null,
  Localization geography null
)

create table dbo.Addresses (
  Id int identity not null primary key clustered (Id),
  CityId int not null,
  Street nvarchar (100) null,
  PostalCode nvarchar (100) null,
)

create table dbo.Cities (
  Id int identity not null primary key clustered (Id),
  Name nvarchar (100) null
)

I have two questions:

Should I move the Localization from Places and Persons to Address?
I am doing this way because I can have an address and not a Localization or vice versa.
Is there a way to improve my database scheme?
Comment: Probably better suited for http://dba.stackexchange.com/
Answer: I would remove Localization from Persons.  It exists in Places.
You say a Person may have an address, a localization, both, or none?  If that is true, then make Persons.AddressID nullable (if it is valid to not have an address).  Also, add a PlacesID (nullable) to Persons.
Answer: You database model looks fine to me. Only that AddressId must be nullable in Persons and Places, as its optional. As you say you will always only have either have an address or latitude / longitude, it seems perfect. But you should add a check constraint on both Persons and Places to ensure not to have both fields filled at the same time.
If, however, you think you might want some time to be able to store both address and latitude / longitude for a person or place, you would want to move Localization to address, because it then is an integral part thereof. If you kept your datamodel as is, you could get inconsistencies by changing an address and not changing the corresponding localization (or vice versa). When moving the localization to address, its cityid would have to be made nullable then of course, because you may have "addresses" that only consist of latitude / logitude with the city unknown.
As to the overall design: Will persons and places differ much from each other? So far they contain the same columns. Hence you may want to use one table PersonOrPlace only instead and add a type column saying whether an entry is a person or a place (or have a flag IsPerson instead).
Comment: Yes, Places and Persons will differ a lot ... I just posted an example.

SQL table for Address and Localization


tempo of fantasia in D-minor from Mozart

Question: Fantasia in D-Minor from Mozart K397 is written in 2/2 (alla breve). The first part of it should be played Andante (let's say 80 half notes in one minute). In reality, it is played much much slower and it is more played as it would be 4/4.
The same is to some extent true for the first movement of the Moonlight sonata, and maybe there are other examples that I'm currently not aware of.
So what explains the difference in the tempo indicated and the tempo used by most pianists? Why are the pieces more played as it would be 4/4 instead of 2/2?
Answer: In Right Before Your Eyes: A Fresh Approach to Interpreting a Piano Score, Ruth Price reasons at length about the tempo of this movement (Chapter 6). It's extremely personal and subjective and makes no attempt at scholarship (it needs to "feel meditative"), but it makes a good point that sometimes specific musical qualities influence the choice of tempo.
A more scholarly viewpoint is Helmut Breidenstein's Mozart's Tempo-System: A Handbook for Practice and Theory. It makes it clear that, for one thing, it gets horribly complicated when figuring out what alla breve is all about, and that "Andante" can mean a lot of things.

Contrary to our habit, the tempo word alone was no "tempo indication in the late 18th century. ... "Andante" in the 18th century does not mean the stride or walking pace of a human being but the incorporeal pace of the music, a "walking motion" in the sense of a regular progression of time.
In 1786 Friedrich Nicolai reports on the significant differences in the performance practice of Andante between Berlin, Dresden, and Vienna. In general, however, the 18th century regarded Andante as "the tempo which keeps the mean between swift and slow." It was only in the 19th century that Andante received the meaning of "slow," which influenced Mozart interpretation disastrously from then on."

Taking both Price's and Breidenstein's points together, that adds up to:

Although there may be significant interpretive practice giving this movement a fairly slow pace, you can definitely use a historical argument to take a faster tempo;
Given the confusion about cut time, you don't have to feel compelled solely by the cut time marking to take a certain tempo; and
There is such a thing as "too fast for the music." Don't hurt anything!
Answer: There is a fallacy in the question: The Mozart D Minor Fantasy is written in common time (i.e., 4/4). This can be confirmed by browsing the various editions on IMSLP.
The primary exception to this (on IMSLP) is a Soviet-era score from Russia, which is given in cut time. However, such scores are notorious for containing errors and should not be considered a reliable source.
Comment: @Rian BTW, does the Henle include any commentary regarding the time signature?
Comment: I'm using a Henle Urtext publication as a reference.... and even then, the question in general (for the Beethoven Sonata) remains valid
Comment: @Rian Fair enough. Suggest you edit your question (the title particularly) to focus on the general issue. Also, mention the Henle (including an image, if possible), so you don't get people like me calling the edition into question.
Answer: First, "of course", pianists who feel sufficiently confident to make their own interpretation choices will do so! :)
Incidental to that is what I see as a sort of backlash against aggressively up-tempo interpretations that don't really sound any better, by any means, but are more "virtuosic".
Second, editors of editions do make many changes to original markings, or insert markings where there were none in the original.
Third, though I've not researched this, I vaguely recall some scholar asserting that Beethoven (for example) inserted rather fanciful metronome markings (tending to be too fast), because the metronome was a new, cool thing, but/and he'd never really used one. Plausible.


Como varrer os dados de uma planilha do Excel

Question: Tenho um banco de dados Mysql e quero pegar os dados de uma planilha do excel e enviar pra ele.
Já sei como salvar os dados na tabela, só falta saber como varrer a planilha e pegar os dados.
Answer: Recomendo usar o SpreadsheetLight.
É bem simples de usar e rasoavelmente bem documentado.
Basta baixar o fonte no site oficial e anexar na sua solução - infelizmente não há NuGet package oficial para ele.
Segue o exeplo de como modificar uma planilha já existente:
    class Program
    {
        static void Main(string[] args)
        {
            // SpreadsheetLight works on the idea of a currently selected worksheet.
            // If no worksheet name is provided on opening an existing spreadsheet,
            // the first available worksheet is selected.
            SLDocument sl = new SLDocument("ModifyExistingSpreadsheetOriginal.xlsx", "Sheet2");

            sl.SetCellValue("E6", "Let's party!!!!111!!!1");

            sl.SelectWorksheet("Sheet3");
            sl.SetCellValue("E6", "Before anyone calls the popo!");

            sl.AddWorksheet("DanceFloor");
            sl.SetCellValue("B4", "Who let the dogs out?");
            sl.SetCellValue("B5", "Woof!");

            sl.SaveAs("ModifyExistingSpreadsheetModified.xlsx");

            Console.WriteLine("End of program");
            Console.ReadLine();
        }
    }

No site deles tem vários exemplos de como realizar várias outras tarefas.
Comment: Vc pode sim, mas e um tanto chato gerir. Planilhas, documentos e apresentações hoje são todos no mesmo formato, o [Office Open XML](https://en.wikipedia.org/wiki/Office_Open_XML). Então para distinguir cada um - salvo pela extensao do arquivo - é bem chato. Mas todos não passam de arquivos XML compactados. Vc pode criar uma rotina para descompactar o arquivos e depois trabalhar com XmlDocument, mas não será uma experiencia muito agradável.
Comment: vou pesquisar sim, valeu. porém, pelo fato do Visual Studio ser da microsoft, pensei que teria códigos próprios sem precisar de programas externos.
Comment: usei o código do Virginio (que não precisa de programas externos) e funcionou de boa. mesmo assim, sou grato pelo tempo dedicado
Answer: Abra o excel e aperte Alt+F11 par entrar na plataforma para programar em VBA.
Crie uma conexão ODBC para conectar ao banco de dados.
Para fazer o loop. poderá fazer da seguinte forma
Crie um módulo e use o código abaixo
Sub CadastraBD()
Dim Planilha As Worksheet
Set Planilha = Plan1 ' Plan1 é a Planilha/Worksheet

'VARRE DA LINHA1 A ULTIMA LINHA
For x = 1 To UltimaLinha(Planilha, 1)
    ColunaA = Range("A" & x)
    ColunaB = Range("B" & x)
    ColunaC = Range("C" & x)
    ColunaD = Range("D" & x)
    ColunaE = Range("E" & x)
Next
End Sub

Public Function UltimaLinha(PLAN As Worksheet, COLUNA As Integer)
    UltimaLinha = PLAN.Cells(65000, COLUNA).End(xlUp).Row
End Function

Comment: obrigado pela dica
Answer: Existe uma forma básica de fazer essa leitura de planilhas do Excel (*.xls e *.xlsx) mas, o provider deve estar instalado na máquina para funcionar. Nesse exemplo de duas ConnectionString uma para xls e outra para xlsx, dependendo do provider pode mudar alguns variaveis dessa ConnectionString.
Planilha Exemplo:

Codigo para leitura dessa planilha
using System.Data.OleDB;

    //String de Conexao
    string ConnectionString = @"provider=Microsoft.Jet.OLEDB.4.0;Data Source='c:\Temp\NamesV1.xls';Extended Properties=Excel 8.0;";
    //string ConnectionString = @"Provider=Microsoft.ACE.OLEDB.12.0;Data Source=c:\Temp\Names.xlsx;Extended Properties=\""Excel 12.0 Xml; HDR = YES""\";

//Código
using (OleDbConnection db = new OleDbConnection(ConnectionString))
using (OleDbCommand command = db.CreateCommand())
{
    db.Open();
    command.CommandType = System.Data.CommandType.Text;
    command.CommandText = "SELECT * FROM [Sheet1$]";

    using (OleDbDataReader reader = command.ExecuteReader())
    {
        if (reader.HasRows)
        {
            while(reader.Read())
            {
                System.Console.WriteLine("{0} {1}", reader["Id"], reader["Name"]);
            }
        }
    }

    db.Close();
}

Referencias:

Read Excel file using OLEDB Data Provider in C# .Net
Read and Import Excel File into DataSet
How to insert data to Excel file using OLEDB
OLE DB Tutorial
Comment: valeu, funcionou de boa sem dar problemas. obrigado


Classe protected e public

Question: Qual é o comportamento de uma classe protected?
Qual é o impacto dos modificadores de acesso (especialmente private e protected) nas classes, e quais suas comuns utilizações?
Consigo entender suas funcionalidades quando atribuídas a métodos, propriedades e atributos, mas não consigo enxergar o mesmo quando se trata de uma classe ou interface.
Answer: Uma classe "top-level" (definida diretamente no namespace) não pode ser protected - é um erro de compilação. Você só pode definir classes protected se elas forem definidas dentro de outras classes (como nested classes). O que o modificador faz é que somente a própria classe dentro da qual a sua nested class está definida, ou suas subclasses, podem acessar a sua classe protegida.
Por exemplo:
protected class A { } // não compila - erro

public class B {
    protected class C { }
    private void Metodo1() {
        // Funciona
        var c = new C();
        Console.WriteLine(c);
    }
}

public class D {
    private void Metodo2() {
        var c = new C(); // não compila - erro
        Console.WriteLine(c);
    }
}

public class E : B {
    private void Metodo3() {
        // Funciona
        var c = new B.C();
        Console.WriteLine(c);
    }
}

Classe protected e public