Confidence Interval Questions; and Is that the Best Way

Question: My understanding of confidence intervals (CI) is that you take a sample from a population of size $n$. Then for that particular ($i$th) sample, you calculate its mean, $\bar{X}_i$, and its variance  $\sigma_{\bar{X}_i}=\frac{s}{\sqrt{n}}$ where $s$ is the standard deviation (SD) of the sample.
And then to determine, e.g., a $95$% CI you then might assume a normal distribution and calculate a factor $z$ such that $\bar{X}_i\pm z\times \sigma_{\bar{X}_i}$ will encompass $95$% of the area under the presumed normal distribution.
The implication of the notion of CIs is that if you take a multiplicity of samples of size $n$ that $95$% of them will contain the actual mean of the population.
Assuming what I've written is correct, I have several questions:

Why does the chosen level of the CI play out such that the very same percentage of CIs will contain the mean of the population.
My larger question is since you are taking a multiplicity of samples and calculating their respective means, why not just make use of the distribution of the sample means, which is much more likely to be normal than any one individual sample.

And finally, is there not then some way, using the parameters estimated from the distribution of the sample means, to claim that $\bar{X}\pm z\times \sigma_{\bar{X}}$, will contain the population mean with $95$% certainty?
In a way, I'm questioning the utility of confidence intervals.
Comment: Have a look at the Central Limit Theorem. It will go a long way towards answering your questions.
Comment: @Stephane Rolland Nice edit, especially in the context of ESL. The linguistics segment of your bio reminds me of Murray Gell-Mann. Thirteen fluently, but I thought I saw even more. If you're interested, I think he had an evolution of language project. With regards,
Comment: @user663837 Not that an important edit. On stackexchange sites, there is a sort of culture of brevity and getting right to the point. Questions elements like "Hello everybody, my name is T. , could you help me ... In advance Thanks. Ted Jones" are considered superflous since it is a site dedicated to questions. You could have those words above and after each and every questions on stackexchange sites. For the dot list, it is just a way to tell you there is included markdown formating. For languages, offtopic to the question: I'm nowhere near 13 or 5 fluent languages. My goal is understanding.
Answer: Normal data, $\sigma$ known. If $n$ observations are randomly sampled from a normal population with unknown $\mu$ and known $\sigma,$ then a 95% confidence interval for $\mu$ is of the form $\bar X \pm 1.96\frac{\sigma}{\sqrt{n}},$ where $\bar X$ is the sample mean of the observations.
Example: Consider $n = 10$ random observations from $\mathsf{Norm}(100, 15),$ as simulated in R and put into the vector x below. Suppose you know $\sigma=15,$ and estimate $\mu$ by the sample mean $A = \bar X  = 98.44.$
set.seed(2020)         # for reprodudibility
x = rnorm(10, 100, 15)
summary(x)
   Min. 1st Qu.  Median    Mean 3rd Qu.    Max.
  58.05   86.79  103.14   98.44  109.52  126.39

Then a 95% CI for $\mu$ is $(89.14, 107.74)$. This happens to be one of the 95% of cases in which the CI 'covers' (contails) the population mean $\mu = 100.$
a = mean(x)
CI = a + c(-1.96, 1.96)*15/sqrt(10); CI
[1]  89.14346 107.73765

Normal data, $\sigma$ estimated by $S.$ If $n$ observations are randomly sampled from a normal population with unknown $\mu$ and unknown $\sigma,$ then a 95% confidence interval for $\mu$ is of the form $\bar X \pm t^*\frac{S}{\sqrt{n}},$ where $\bar X$ and $S$ are, respectively, the sample mean and sample stardard deviation, and $t^*$ cuts probability 0.25 from the upper tail of Student's t distribution with $n-1$ degrees of freedom.
Example: Use the same data as above, but now pretend you don't know $\sigma.$
We estimate $\sigma$ by the sample standard deviation $S = 19.36$ and (from R or a printed table of t distributions) $t^* = 2.262.$ Then the expression above gives
the 95% CI $(84.59, 112.29).$ [I have used the R function t.test, which prints out the CI.]
s = sd(x);  s
[1] 19.3592
qt(.975, 9)
[1] 2.262157
t.test(x)$conf.int
[1] 84.59182 112.28929
attr(,"conf.level")
[1] 0.95

Nonnormal data. If data are not normal or if you are trying something other than the population mean $\mu,$ then different styles of confidence intervals may be appropriate.  If the sample is large enough that $\bar X$ is nearly normal then one of the confidence intervals above may be a useful approximation.
Example: Consider $n=500$ observations from an exponential distribution with rate
$\lambda = .01$ and $\mu = \sigma = 100.$ The exponential distribution is severely right-skewed and far from normal. But the average of a large exponential sample is roughly normal.
The 95% t confidence interval provides as approximate 95% CI $(93.07, 111.46)$ in this case.
However, it is best to use the exact 95% CI
$(93.86, 111.86)$
for $\sigma,$ based on a gamma distribution. Because the gamma distribution is not symmetrical, the exact CI is not centered exactly at $\bar Y = 103.17.$ (In this example, both the approximate CI and the
exact CI happen to include the true value $\mu = 100.)$
set.seed(411)
y = rexp(500, .01)
summary(y);  a = mean(y)
    Min.  1st Qu.   Median     Mean  3rd Qu.     Max.
  0.2361  32.3471  73.6159 103.1729 143.8860 596.2742
[1] 97.17857
t.test(y)$conf.int
[1] 93.07353 111.45858

attr(,"conf.level")
[1] 0.95
a/qgamma(c(.975,.025), 500, 500)
[1]  93.86247 111.85700

Answer: On your first question: Why does the chosen level of the CI play out such that the very same percentage of CIs will contain the mean of the population?  This is not always the correct interpretation, so I present more on the underlying varying concepts associated with confidence intervals. To quote from Wikipedia:

The confidence interval can be expressed in terms of samples (or repeated samples): "Were this procedure to be repeated on numerous samples, the fraction of calculated confidence intervals (which would differ for each sample) that encompass the true population parameter would tend toward 90%."[2]
The confidence interval can be expressed in terms of a single sample: "There is a 90% probability that the calculated confidence interval from some future experiment encompasses the true value of the population parameter." Note this is a probability statement about the confidence interval, not the population parameter...Here the experimenter sets out the way in which they intend to calculate a confidence interval and to know, before they do the actual experiment, that the interval they will end up calculating has a particular chance of covering the true but unknown value.[4] This is very similar to the "repeated sample" interpretation above, except that it avoids relying on considering hypothetical repeats of a sampling procedure that may not be repeatable in any meaningful sense.
The explanation of a confidence interval can amount to something like: "The confidence interval represents values for the population parameter for which the difference between the parameter and the observed estimate is not statistically significant at the 10% level".[7] In fact, this relates to one particular way in which a confidence interval may be constructed.
  In each of the above, the following applies: If the true value of the parameter lies outside the 90% confidence interval, then a sampling event has occurred (namely, obtaining a point estimate of the parameter at least this far from the true parameter value) which had a probability of 10% (or less) of happening by chance.

Also, some important points covered under misunderstanding, to quote further:

Misunderstandings
A 95% confidence level does not mean that for a given realized interval there is a 95% probability that the population parameter lies within the interval (i.e., a 95% probability that the interval covers the population parameter).[13] According to the strict frequentist interpretation, once an interval is calculated, this interval either covers the parameter value or it does not; it is no longer a matter of probability. The 95% probability relates to the reliability of the estimation procedure, not to a specific calculated interval.[14]

Note, there is also Bayesian inference in the form of so-called credible intervals. Per Wikipedia again:

Confidence intervals correspond to a chosen rule for determining the confidence bounds, where this rule is essentially determined before any data are obtained, or before an experiment is done. The rule is defined such that over all possible datasets that might be obtained, there is a high probability ("high" is specifically quantified) that the interval determined by the rule will include the true value of the quantity under consideration. The Bayesian approach appears to offer intervals that can, subject to acceptance of an interpretation of "probability" as Bayesian probability, be interpreted as meaning that the specific interval calculated from a given dataset has a particular probability of including the true value, conditional on the data and other information available. The confidence interval approach does not allow this since in this formulation and at this same stage, both the bounds of the interval and the true values are fixed values, and there is no randomness involved. On the other hand, the Bayesian approach is only as valid as the prior probability used in the computation, whereas the confidence interval does not depend on assumptions about the prior probability.

To answer your larger question, "why not just make use of the distribution of the sample means, which is much more likely to be normal than any one individual sample", you are actually right if the samples are from a uniform distribution. In fact, an approximate way to generate random normal deviates is to average 12 deviates from a uniform distribution. However, a more efficient path is to employ a transformation (employing, for example, a Box-Cox power transformation, see discussion here) is induce normality and not lose so many degrees of freedom. If the data has percentage errors, a log transform is recommended.
Answer:
since you are taking a multiplicity of samples and calculating their
  respective means, why not just make use of the distribution of the
  sample means

Great intuition! Notice that the equations for confidence intervals only require one sample, however. If we could gather many samples of a good size, we would. Usually, it is difficult or impossible to gather more data (we cannot gather more data under the exact conditions that held yesterday, for example), and confidence intervals are one way to quantify uncertainty in this usual case.
Answer: Let me fill some gaps:

Let's take a set of samples (of size $n$) from a single population, and calculate the mean of each sample separately, $\{\overline X_i\}_{i=1,...,m}$ where $m$ is the number of how many different samples we took.
Since each $\overline X_i$ is calculated from a subset of the population, $\overline X_i$ is a function of the data points in the $i$th sample, but since we have chosen the members of $i$th sample randomly, $\overline X_i$ is a random function.
We assume that the distribution of each $\overline X_i$ is a normal distribution with the same mean and variance.
(for an appropriately chosen $z$) %95 of the values $\{\overline X_i\}_{i=1,..m}$ will not be in $\overline X_j \pm z \sigma_j$ because once you took $m$ samples of size $n$ from a single population, those values are not random variables anymore, they are just real numbers. However, the probability of any $\overline X_k$ being in $\overline X_j \pm z \sigma_j$  will be %95. Hence,

Now, why CI is an important concept?
Because it gives you an estimation of your errors. Think about it; for example, if I tell you the distance between two points without telling you how confident I am about the information I gave, how can you use that information (compare $100m \pm 90m$ and $100m \pm 1m$)?


How many hp dl360 g7 in a rack?

Question: It might sound as "how long is a piece of string"?
In my current job the process is to leave 1U spacing, with no blinders, between servers; this incurs a considerable loss of space, no event sparking about turbulent air flow. Everyone is adamant that's the way to go and I have hard time making my case for a no spacing approach to rack-filling.
What's your experience? Provided that the AC air flow is fine and tile floor robust, how many hp servers have you managed to put into a 42U rack?
I'd love to have hp official recommendations, if anyone has a link to share.
Thank you,
-A
Ps: google search didn't really give usefull info...
Answer: You can fill a 42U rack with ProLiant servers as long as you have the power distribution and cooling coverage to support it.
Cold air is drawn-in from the front and exhausted out the rear of the chassis. ProLiant servers have a high thermal tolerance and this is a supported setup.
Reasons for leaving space/blank panels can include aesthetics, ease of maintenance, cabling, etc... but there's no harm in stacking the systems.
Also see: Rack Mounting a Server with hot air vents on the top? where I give an  example using G7 ProLiants.
Comment: Email your HP sales guys, say "Could you provide pricing for a single 43U rack filled with 42 x DL360's including support please", when they send in the quote you have your answer as their quotes have to be signed off by technical presales.
Comment: Get HP sales involved, they'll help you if they know there's an order in the pipeline.
Comment: Right Alex, only just got an official word back. The WILL work stacked on top of each other BUT 'best practice' is to leave a gap - you you/me AND your colleagues are both right and wrong. Sorry this doesn't conclusively answer your question but the key part is they WILL support 42 1U servers in a rack, they might just moan about it not being 'best practice'.
Comment: Yeah - like I say though, what they support and what they write in a 'best practices' are very different things.
Comment: Precisely... But that doesn't seem to convince anyone here. It's up to the point where they think that stacking the servers will prevent proper heat dissipation. I think they just need something like a white paper to cover their ass.
Comment: Get your HP rep to find you a whitepaper or an expert.
Comment: Jinx! (10 more chars)
Comment: Ok, that's exactly what the guys here say. The top-vent lead everyone to think that there must be spacing, which I think is incorrect. Until I get an official hp recommendation that's not going to change. Did you get your hands on such document?
Comment: The vent is passive ventilation for the PCIe slots on the DL360 G7. The *DL380 G7*, for instance, does not have such vents.
Comment: I'd love to have the hp guy, but it's controlled by another department, so no account number available. Plus the guy who makes the company recommendation just doesn't want to hear anything about it(20 years experience ossified in his job)....
Comment: Then check on the [HP support forums](http://h30499.www3.hp.com/t5/Planning/HP-DL360G7-server-rack-mounting-without-skipping-a-gap-between/td-p/5499735#.T-INHytYvYA) to get an expert answer.
Comment: I have a dedicated HP sale team, I'll drop them a line but they may take a while. Oh and I meant 42U above, typo!
Comment: @Chopper3 : that would be almost a god send! :)
Comment: Sent the email, it's 19:30pm in the UK, I'll let you know what they say. It's 'godsend' btw ;)
Comment: @chopper3 Did they give a reason for needing/wanting the gap?
Comment: No, just 'best practice' - quite surprised myself.
Comment: @Chopper3: woo, this is really surprising, considering that the immediate consequence is to double a server deployment footprint.  Collocation turns very expensive this way. My 20-year-old-experienced-ossified colleague will smile... Damnit. I just can't figure out why they say this? Not even speaking about the number of racks I've seen in previous jobs with servers stacked on one another. plus, if you have to use blanking panels, what's the point of leaving a gap? This leaves a layer of hot air that's never cooled properly. Not the answer I wanted, but it is what it is.. Thanks a bunch!
Answer: If you have the power outlets and cooling capacity you can fill a 42U rack with 42 of those servers, I've seen it done - and HP will support it - but to be honest it was needlessly heavy and was replaced by blades very quickly afterwards - would that be an option, or SL's for that matter.
Obviously in your case you're limited to 22.
Comment: True, it's always good to leave up to 4u spacing at the bottom for the cable slack etc..
Answer: Get blades if you are worried about space.
Comment: The specific requirement for HP DL360 G7s suggests that the hardware might have already been purchased before the question was asked.  It was asked a bit over a year ago so new answers are unlikely to be helpful.
Answer: The 1U vertical air gap between servers is reputable to stop the server below adding extra heat to the server above. Any its also best practise to put blanking plates on these gaps. So that the cool air in the front passes more efficiently through the server.
As for this 1U vertical gap, I've never seen any supporting material, so Ill take it with a pinch of salt and would be happy to forget it if research disproved this hypothesis. Its a moot point at our place as we couldnt power a full rack.
Comment: I strongly dispute this answer - HP specifically states that they support racks FULL of servers and that no spacing is required. In fact not only do they sell fully built rack completely full of servers with no gaps but I've bought a few like this. The spend a huge amount of time ensuring that all heat is vented rearwards to allow them to do this - other brands may not and thus may have this restriction.
Comment: You dispute that some manufactures say leave a gap? I've heard it plenty, and when I pushed the for a why, I was told that. Perhaps you could ask why too. I'd like to see best practise be based on research too.
Comment: Not at all - I dispute that HP say to leave a gap. As I state some servers aren't as well designed so probably do leak heat upwards - HP specifically design theirs not to - but this question is about a particular HP model that does support 42 servers in a 42U rack as detailed in their documentation.
Comment: I dispute it too, I've been long enough in telco shelters to say that filling up the full 42 U should be fine, provided there's a proper cooling system, and power capacity. I think the HP sales guy just didn't want to deal with an installation lacking adequate cooling system. Spacing at the bottom/middle is required to accomodate the cable slack, end up with 34 to 38 U used, that's all. But there is no reason in the world to impose 1U spacing, considering this doubles the hostings costs. Dell provides 42U support with similar server cooling design, HP sales are just sissies.

How many hp dl360 g7 in a rack?


How to iterate through objects in a class?

Question: For a script I'm writing I would like to be able to something like this.
class foo:
    __init__(self):
        self.a = 'path1'
        self.b = f'{self.a}path2'

bar = foo()

for i in bar:
    if not os.path.isdir(i):
        os.mkdir(i)

But I can't quite figure out how to make the class iterate through the objects.
Comment: Do the answers to this [question](https://stackoverflow.com/questions/19151/how-to-build-a-basic-iterator) help at all?
Answer: Is this what you need?
class foo:
    def __init__(self):
        self.a = 'string1'
        self.b = f'{self.a}string2'

bar = foo()

for attr, value in bar.__dict__.items():
        print(attr, value)

Answer: I think this will answer your question.
class foo:
    def __init__(self):
        self.a = 'string1'
        self.b = f'{self.a}string2'

bar = foo()

for i in dir(bar):
    print("obj.%s = %r" % (i, getattr(bar, i)))

# obj.__class__ = <class '__main__.foo'>
# obj.__delattr__ = <method-wrapper '__delattr__' of foo object at 0x000001C28C2A3B80>
# obj.__dict__ = {'a': 'string1', 'b': 'string1string2'}
# obj.__dir__ = <built-in method __dir__ of foo object at 0x000001C28C2A3B80>
# [...]
# obj.a = 'string1'
# obj.b = 'string1string2'


Como criar um atalho para abrir um site no navegador?

Question: Preciso criar um atalho para abrir o navegador com o endereço (no caso, o Chrome).
Answer: Pra fazer o que você quer, você precisa criar um atalho do Windows. Se o atalho apontar para um endereço Web, o navegador padrão do sistema será aberto, com uma nova aba já focada e a carregar o endereço indicado no atalho.
Para criar um atalho do Windows programaticamente, você pode usar a ferramenta MKLINK do sistema. Você pode fazer um programa na sua linguagem preferida que invoque esse programa, com os parâmetros necessários (detalhados no link acima).
Caso você queira fazer isso em outro sistema operacional, edite a pergunta pra incluir essa informação, ok?
Comment: é um VBS que preciso, mas precisava fazer isso no Android
Comment: Nesse caso eu recomendo que você dê uma olhada nesse link, de uma pergunta no SO matriz: http://stackoverflow.com/questions/5676090/android-is-there-a-programming-way-to-create-a-web-shortcut-on-home-screen . O que você quer é possível, tem só que seguir os passos indicados nas respostas de lá.


SQL Trigger after insert not working

Question: I tried to write a trigger that updates the data after an insert.
I'm using the SQL Server 2016 Import Export Data tool to transfer my data from Excel into the database.
After the import I need to run a few update statements.
I can save my trigger, but it's not updating any data. Where is my fault?
Trigger:
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO

ALTER TRIGGER [dbo].[TRG_InsertMappinng]
   ON  [dbo].[T_CCG_MBR2017_Across]
   AFTER  INSERT
AS
BEGIN
    SET NOCOUNT ON;

    UPDATE  [DB_CC_FC_Database_SQL].[dbo].[T_CCG_MBR2017_Across]
    SET [Colum1] = 'Text1'
    Where [Colum1] IS NULL
    AND [Colum2] = 'Text2'
    AND [Colum3] = 'Text3'
    AND [Colum4] = 'Text4'

END

Comment: does this query UPDATE  [DB_CC_FC_Database_SQL].[dbo].[T_CCG_MBR2017_Across] SET [Colum1] = 'Text1'
    Where [Colum1] IS NULL AND [Colum2] = 'Text2' AND [Colum3] = 'Text3' AND [Colum4] = 'Text4'
 do something when used outside trigger ?
Comment: Yes, it works when I run it without the trigger!
Comment: Select all the Inserted value In A Variable And Then Update IT.how this works for you
Comment: Thank you, but I don't think this helps. I just used a simple insert statement and my trigger works perfectly. It just doesn't work with the data import tool...
Answer: If your code is working outside the trigger, but not within the trigger, it could just be that the trigger is disabled. Try enabling it, and run it again to test.
ENABLE TRIGGER [dbo].[TRG_InsertMappinng]
    ON [dbo].[T_CCG_MBR2017_Across];

Comment: Thank you, but it didn't change anything. Seems like the data import doen't count as an insert.
Comment: I just used a simple insert statement and the trigger works perfectly. It just doesn't work with the data import tool...
Answer: As written here, th SQL Import Export Data Tool doesn't fire any trigger. You can find more information about that here.

SQL Trigger after insert not working


Bootstrap Modal: Make body contents full width of modal

Question: I'm working to create a 'zoom' option on my webapp that will copy a (google) chart into a modal, but I want the chart to expand to the full width of the modal.
My plain-vanilla modal:

-

              <button type="button" class="close" data-dismiss="modal" aria-label="Close">
                ×
              </button>

-

              <button type="button" class="btn btn-secondary" data-dismiss="modal">Close</button>

and the Javascript that I am using to pluck a chart out of the document:
$('.modal-chart').dblclick(function() {
    let chartTitle = this.children.item(0).innerText;
    let chartDiv = this.children.item(1).id;
    chartDiv = '#' + chartDiv;
    $('#chartModal').find('.modal-title').text(chartTitle);
    $('.modal-body').html($(chartDiv).html());
    $('#chartModal').modal('show');
})

I'm wondering where to apply some css to have the chart fill the width of the modal:
Comment: Try assigning width 100% to chartDiv element.
Comment: Thanks, I did try:`$(chartDiv).css({width: '100%'});` but that didn't seem to work.
Comment: It would be better if you can post a codepen link. Using bootstrap modal, if modal-dialogue has max-width:100% then block elements inside modal body will inherit width:100% by default.
Comment: Hope this link helps, I have test it and it works, https://stackoverflow.com/questions/48560029/google-chart-value-going-outside-from-pie-chart-in-bootstrap-modal
Answer:
you can give position relative to parent div and give position absolute to your Child div

.modal-body{
 Position:relative;
}
 $(chartDiv).css({top:'0';right:'0';bottom:'0';left:'0';})


Get values for a matching key recursively from object

Question: I have this json object
{
  "data": {
    "user": {
      "user_info": {
        "id": "AoGC2HQ9vedHmzcMX"
      },
      "product": [
        {
          "node": {
            "id": "NzcxNzU2ODU1ODM1",
            "feedback": {
              "raters": {
                "nodes": [
                  {
                    "id": "1",
                    "name": "Dan"
                  },
                  {
                    "id": "2",
                    "name": "Allen"
                  },
                  {
                    "id": "3",
                    "name": "Williams"
                  }
                ]
              },
              "commentors": {
                "nodes": [
                  {
                    "id": "001",
                    "name": "Kent"
                  },
                  {
                    "id": "002",
                    "name": "Jay"
                  }
                ]
              }
            }
          }
        }
      ]
    }
  }
}

So how do I make it to get values of id If the parent property matches the desired key name, In this example I want to get all id's from raters.nodes only.
so expected result is
[1,2,3]

I know can do obj.data.user.product[0].node.feedback.raters.nodes and loop through that, but that is not how I want and the object tree occasionally changes.
I have used this recursive function
const recursiveSearch = (obj, searchKey, results = []) => {
   const r = results;
   Object.keys(obj).forEach(key => {
      const value = obj[key];
      if(key === searchKey && typeof value !== 'object'){
         r.push(value);
      }else if(typeof value === 'object'){
         recursiveSearch(value, searchKey, r);
      }
   });
   return r;
};

//returns all id's

While it works, it returns all id values, so how do I improve it? If not, how do I make this possible?
Answer: I think you want to really do this in 2 steps,..
First make a function to get the root node your looking for, and then you can just use map like normal.
Below is an example.

var data = JSON.parse("{\"data\":{\"user\":{\"user_info\":{\"id\":\"AoGC2HQ9vedHmzcMX\"},\"product\":[{\"node\":{\"id\":\"NzcxNzU2ODU1ODM1\",\"feedback\":{\"raters\":{\"nodes\":[{\"id\":\"1\",\"name\":\"Dan\"},{\"id\":\"2\",\"name\":\"Allen\"},{\"id\":\"3\",\"name\":\"Williams\"}]},\"commentors\":{\"nodes\":[{\"id\":\"001\",\"name\":\"Kent\"},{\"id\":\"002\",\"name\":\"Jay\"}]}}}}]}}}");

function getRoot(data, search) {
  function get(path, data) {
    for (const [k, v] of Object.entries(data)) {
      if (v instanceof Object) {
        const pp = `${path}.${k}`;
        if (pp.slice(-search.length) === search) {
          return v;
        }
        const r = get(`${path}.${k}`, v);
        if (r) return r;
      }
    }
  }
  return get('', data);
}

const r = getRoot(data, 'raters.nodes');
console.log(r && r.map(i => i.id));
Comment: I see, what If there are multiple raters.nodes ?


Faster way to merge multiple files with unequal number of rows by column in bash

Question: I have a multiple files that I want to merge by column using shell script, let's say file a.txt and file b.txt. File a.txt contains sorted unique value and the first column will be used as a reference value.
example :
# cat a.txt
001|johan
002|mike
003|adam

# cat b.txt
001|chu
001|stewart
002|lewis
002|jordan
003|lambert
003|johnson
003|smith
003|long

The both files will be combined to produce an output like below.
# cat c.txt
001|johan chu
001|johan stewart
002|mike lewis
002|mike jordan
003|adam lambert
003|adam johnson
003|adam smith
003|adam long

I tried simple iteration using while do.
while read line
do
  ids=`echo $line | awk -F"|" '{print $1}'`
  fn=`grep $ids a.txt`
  echo $fn"|"$line | awk -F"|" '{print $1"|"$2" "$4}'
done  c.txt

But it takes a lot of time if I have million number of rows.
In MySQL we can easily achieve it using JOIN clause. But we need to load/insert them first.
Faster approach is probably using paste command, but as far as I know, the total rows of both files must be equal. Well I can adjust a.txt first. But still comsumes a lot of time when the script running.
Maybe someone has a better approach.
Answer: You could put all in one awk script:
awk -F'|' '{if (NR==FNR) a[$1]=$2; else print $1 "|" a[$1] " " $2}' a.txt b.txt

001|johan chu
001|johan stewart
002|mike lewis
002|mike jordan
003|adam lambert
003|adam johnson
003|adam smith
003|adam long

Comment: I didn't know `awk` could do such a thing. Splendid. Thank you very much.
Answer: Assumptions:

both files are sorted by the 1st column
ignore rows that do not have a match in the opposite file

One idea using join and sed (to remove the 2nd |):
join -t'|' -o 1.1,1.2,2.2 a.txt b.txt | sed -E 's/\|([^|]*$)/ \1/'

One awk idea:
awk '
BEGIN   { FS=OFS="|" }
FNR==NR { a[$1]=$2; next }
$1 in a { print $1,a[$1] " " $2 }
' a.txt b.txt

Both of these generate:
001|johan chu
001|johan stewart
002|mike lewis
002|mike jordan
003|adam lambert
003|adam johnson
003|adam smith
003|adam long


How to determine the modules enabled on a third party website?

Question: When I don't have the admin access to a site, how can I find out the modules that are enabled on the site.
For example : How can I identify various modules enabled on www.drupal.org
Answer: There are various you can find this out. But none of them are foolproof and they are just dirty tricks at best.
You can check source(view source) of the website and do the following.

Check the css includes in the head tag and figure out the modules from path.
Check the javascript includes in the head tag and figure out the modules from the path.
Check the classes of html tags from the body tag.
Do the above for multiple standard pages and you should be able to make a list of at-least 50% of the websites based on your knowledge of the modules.

But the easiest of them all is using the http://www.drupalxray.com/ website. Looks like they have automated many rules like the above and search enough paths to prepare a pretty exhaustive list of modules used on a website.
Comment: @GokulNK If the site is pre 7.32 then it'd be easy! But yeah, not possible otherwise. They can only be going off of markup and/or file structure. Nothing else would make sense. It'd be easy to find out, actually - set up a test site with full request logging, then let Xray loose on it. Inspecting the access logs will tell you what they've used to make decisions
Comment: @Clive I enabled the access logs and looks like they are targeting the static files in the modules. They are using HEAD requests to check the presence of the static files.
PatrickKenny what you mentioned was right. They are not targeting the database urls. They are targeting the static files in the modules and hence even if a module is not enabled, drupalxray.com would still list them :)
Comment: Drupal Xray is really interesting-- I just scanned my site with it, and it even reveals modules that are in the codebase but not enabled.
Comment: @PatrickKenny how on earth can it scan the modules in your codebase? I am assuming you must have enabled those modules sometime and then disabled them, hence leaving some traces in the database.
Comment: @Clive Thanks for the suggestion. I was really curious about what they are using. In fact checked their AJAX calls but was not able to make much out of it. Your pointer regarding access logs makes sense. On it now ;)
Comment: Site isn't available.


Dismiss iOS keyboard extension when app running it is minimised

Question: I am working on a iOS keyboard extension. It works fine, but the run-time memory used by it gets almost double if I minimize any current app and open the keyboard in another app.
To explain it better, let me give you an example.
Suppose I opened the keyboard in the "Notes" app, it takes around 15 MB(first launch). Now if I minimize "Notes" and open the keyboard in "Safari", the memory goes to 21 MB.
So, my question is that is there any way to dismiss the keyboard if the app running it is minimised?
Any help is appreciated. Thanks
Answer: You could sign up for the NSExtensionHostWillEnterBackground / NSExtensionHostWillResignActive notifications, and compare the extension context object to your UIInputViewController's extension context object to see that the host app of any individual input view controller is disappearing.
With that said, it sounds like you're leaking your UIInputViewController subclass, or at least some of its contents.
You should profile your keyboard extension for leaks/heap growth and ensure that any resources that are only needed by one instance of the keyboard are deallocated by the time its input view has been hidden.
Answer: In your AppDelegate.m :
- (void)applicationDidEnterBackground:(UIApplication *)application{
   [self.window endEditing:YES];
}

Comment: Sorry this is a custom keyboard, it doesn't have an AppDelegate. It has a UIInputViewController. Is there any method in `UIInputViewController` which does the same as `applicationDidEnterBackground` ?


Invalid advertisement payload detected

Question: I am trying to advertise a UUID in my UWP app with BLE, so other devices can scan for it and find it. Here is my code to advertise:
    // Start advertisement

    if (_publisher == null)
    {
        _publisher = new BluetoothLEAdvertisementPublisher();
    }

    // We need to add some payload to the advertisement. A publisher without any payload
    // or with invalid ones cannot be started. We only need to configure the payload once
    // for any publisher.

    // Add a manufacturer-specific section:
    // First, let create a manufacturer data section
    var manufacturerData = new BluetoothLEManufacturerData();

    // Then, set the company ID for the manufacturer data. Here we picked an unused value: 0xFFFE
    manufacturerData.CompanyId = 0xFFFE;

    // Finally set the data payload within the manufacturer-specific section

    // Here, use a 16-bit UUID: 0x1234 -> {0x34, 0x12} (little-endian)
    var writer = new DataWriter();
    UInt16 uuidData = 0x1234;
    writer.WriteUInt16(uuidData);

    // Make sure that the buffer length can fit within an advertisement payload. Otherwise you will get an exception.
    manufacturerData.Data = writer.DetachBuffer();

    // Add the manufacturer data to the advertisement publisher:
    _publisher.Advertisement.ManufacturerData.Add(manufacturerData);

    string serviceUuid = $"11111111-1234-1234-1234-000000000000";

    _advertisementUuid = new Guid(serviceUuid);

    _publisher.Advertisement.ServiceUuids.Add(_advertisementUuid);

    _publisher.StatusChanged -= Publisher_StatusChanged;
    _publisher.StatusChanged += Publisher_StatusChanged;

    _publisher.Start();

It throws this exception when I call Start():

The data is invalid - Invalid advertisement payload detected
Answer: As described in MSDN: https://learn.microsoft.com/en-us/uwp/api/windows.devices.bluetooth.advertisement.bluetoothleadvertisementpublisher
The UUID advertisement is not supported
The following advertisement types are system-reserved and are not allowed:
Flags (0x01)
Incomplete List of 16-bit Service UUIDs (0x02)
Complete List of 16-bit Service UUIDs (0x03)
Incomplete List of 32-bit Service UUIDs (0x04)
Complete List of 32-bit Service UUIDs (0x05)
Incomplete List of 128-bit Service UUIDs (0x06)
Complete List of 128-bit Service UUIDs (0x07)
Shortened Local Name (0x08)
Complete Local Name (0x09)
Tx Power Level (0x0A)
Class of Device (0x0D)
Simple Pairing Hash C192 (0x0E)
Simple Pairing Randomizer R192 (0x0F)
Security Manager TK Values (0x10)
Security Manager Out-of-Band Flags (0x11)
Slave Connection Interval Range (0x12)
List of 16-bit Service Solicitation UUIDs (0x14)
List of 32-bit Service Solicitation UUIDs (0x1F)
List of 128-bit Service Solicitation UUIDs (0x15)
Service Data 16-bit UUID (0x16)
Service Data 32-bit UUID (0x20)
Service Data 128-bit UUID (0x21)
Public Target Address (0x17)
Random Target Address (0x18)
Appearance (0x19)
Advertising Interval (0x1A)
LE Bluetooth Device Address (0x1B)
LE Role (0x1C)
Simple Pairing Hash C256 (0x1D)
Simple Pairing Randomizer R256 (0x1E)
3D Information Data (0x3D)

Comment: Well. I can understand why it is there (becasue you can read UUIDs in Wantcher mode). But why it is read-write - this is the question. Any way it is so and we can do nothing with that for now.
Comment: But then why is there a `IList ServiceUuids` property? Just to confuse me? lol

Invalid advertisement payload detected


Passing Variables to a MongoDB View

Question: i'm trying to make views in MongoDB to avoid unnecessary returns. In the documentation says that the aggregation functions can take variables with a double dollar sign, taking this in mind i have created a view that in this example should take one variable to filter customerIds and group the results to sum the payments of different documents.
Example:
db.createView(
  "viewName",
  "myCollection",
  [{
    $match: {  "customerId": "$$customerId", }
  },{
    $group: {
      _id: null,
      total: "$amount",
    }
  }]
)

The view is created OK and if i put some valid customerId in the aggregation function that works ok, but i don't have the slightest idea how to execute the view and pass the customerID that i need.
Any ideas? The mongodb documentation does not help me in this situation and i really need to create this as a view, since there are many applications that will connect to this view(s).
I have tried:
    db.viewName.find({customerId: "some valid id"});
Comment: It would be great to hear if you figured this out. I'm looking at the `AggregateOptions` which include the ability to set a `let` value with a variable. However, I'm creating my view through Compass so I get var not found. Tomorrow I will try creating the view programmatically and see if that works.
Answer: You can access it just like a collection, for example I am creating a view via:
db.runCommand({
  create: 'AuthorsView',
  viewOn: 'authors',
  pipeline: [{
    "$group": {
      "_id": "$email",
      "count": {
        "$sum": 1
      }
    }
  }]
})

Since this is now an existing view I can simply do:
db.getCollection('AuthorsView').find({})

To see all the documents or to add more parameters to the find
Not sure what you mean by passing variables since views are just like collections ... you run queries against them via find & aggregate.
Comment: Was there ever a solution found to this? It's exactly what I'm looking for. I have a view that starts with a $match that restricts the data sent into the rest of the pipeline, but i need to pass in a value to the $match.
Comment: The thing here is that the filter method acts after the aggregation pipeline. And by passing variables, i want the view to receive for example, a company id to only calculate the amounts for that company. for example:

`db.myView({companyId: 'somevalidid'})`
Answer: First, you can't pass variables to $match without $expr. There is no error because "$$..." is interpreted as a string.
Second, If we fix things like this:
db.createView(
  "viewName",
  "myCollection",
  [{
    $match: {$expr:{$eq:["$customerId","$$customerId"]}}, }
  },{
    $group: {
      _id: null,
      total: "$amount",
    }
  }]
)

But $$ is not a system variable, so this won't work. You could pass a system variable like $$ROOT or a field path $field.path; the user-defined variables are made up of system variables or collection data.

Passing Variables to a MongoDB View


configure wireshark to automatically save captured packets every X hours

Question: I am capturing traffic using wireshark. Everything works nice, but for some reason after I capture more than 2 mlns packets, wireshark just crashes.
I am not sure what can be the reason, but I tried it three times and every time soon after 2 mlns it crashes. So I am exporting the information every 1 something million packets by using File->Export->File then restarting the capture.
Everything works fine, but is there a way to automatically tell wireshark to Export and restart capture after specific amount of packets or may be specific time limit?
Comment: What OS is your capture platform"
Comment: Windows 7, but the same is happening on Ubuntu
Answer: How much data is flowing across the link you're trying to monitor? Wireshark's primary job is to show you as much information as it can about every packet that it sees and it does this by default. If you're trying to dissect lots of packets in real time you can run out of memory very quickly.
There are a couple of ways around this:

Within Wireshark's capture options, make sure "Update list of packets in real time" is disabled and that "Use multiple files" is enabled.
Instead of using Wireshark use dumpcap. Dumpcap is much more efficient and it's what actually captures packets when you click the "capture" button in Wireshark.

BTW, you might want to save capture files using "Save". Depending on the file format you choose "File→Export" may save packets to a file that Wireshark can't read (hence the word "export").
Comment: Thanks for advice. 'Update list of packets was disabled' about 'Use multiple files' - can you point me where I can change it and what does it do? And for sure many thanks for showing dumpcap. Never heard about it.
Comment: "Use multiple files" is one of the sections in the capture options. You can open the capture options via "Capture→Options" or by clicking on "Capture Options" in the welcome screen.


How to practice chord changes into B major?

Question: I am struggling to play some barre chords, especially this B major one:
E --2--
B --4--
G --4--
D --4--
A --2--
E --x--

I try placing my barring finger (1) on the second fret, and then adding the other fingers on fourth fret (as I think I should do). However, I can only do that with great time and difficulty: fingers 2 and 3 don't "want" to go that far, and get stuck at fret 3.
The same happens when I try putting all fingers on the frets simultaneously (the way that may ultimately be more efficient/faster). I cannot make the proper "configuration" of fingers in the air and when I put it down, fingers 2 and 3 are at fret 3 or halfway to where they should be (fret 4).
So, when I need to play B major, I first put the fingers 2, 3 and 4 down, and then add finger 1 (bar). This works, because when fingers 2, 3 and 4 are set at fret 4, friction stops them from sliding closer to finger 1 (and I feel that they "want" to). However, this is unacceptably slow.
So, what is the proper order of placing the fingers to play the B major chord? How to practice it?
Please note that I don't want to play a different variant of B major. Also (I don't know whether it's relevant) this arose from the chord-changing exercises I was trying to play:
Am-Dm-E-Am (easy)
C-F-G-C    (OK if not too fast)
E-A-B7-E   (not hard)
E-A-B-E    (impossible)

Answer: A couple of points. You don't have to leave out the bottom string. It can still be barred and played on the 2nd fret. You don't have to use three fingers for the strings 2,3 and 4. Obviously, 3 can be used, but you could make do with 2 or even 1, sort of 'barred' across the 3 strings, bent up so that the 1st string still sounds. B7 would work, although you don't want this option - barre across the lot at fret 2, and use fret 4 on 2nd and 4th strings. Works well in key of E.
For a practice regime, you could try the hammer-on technique, which helps put all fingers down simultaneously.
Comment: I disagree about playing the bottom string.  That is an awkward voicing at that low of a pitch, with the 5th in the bass.  Also, that is NOT the chord he is trying to play!  He specifically spelled out the fingering he is attempting, so telling him "just do a different fingering" is not a legit answer to his question "help me do this fingering".
Comment: @WilburWhateley - read the question carefully, then my answer. The individual strings on each fret are not working for the OP, so there's an alternative. There are many different ways to fret specific strings on chords. Options are good things to have.
Comment: Duuuude, careful.  You are really assuming a lot by telling ME to read it carefully.  Here is a quote from his question: `Please note that I don't want to play a different variant of B major.`  He wants help putting his fingers in THAT position.  Options are good to have, he specifically said he doesn't want options.
Comment: @WilburWhateley  I interpret "different variant" as a a different variation of a B chord (say an E shaped barre chord on 7th fret vs A shaped barre chord on 2nd fret).  What Tim is suggesting is a different fingering of the variant of B chord that the OP wishes to play.
Answer: Like with anything else, barre chords take time to play properly. I bet that your 1st finger isn't strong enough to correctly bar the 2nd fret all the way. I suggest figuring out where your limit is (where you can actually play an A shaped barre chord) and try switching to and  from it to get use to it.
A viable option if you need to play this progression asap is to not bar the chord, but instead finger it the following way:
%X/X.2/1.4/2.4/3.4/4.X/X[B]

It's an acceptable way to play a B chord if you need to, but you should eventually be able to play the full chord.
Another possible way you could play a B chord is:
%X/X.2/1.4/3.4/3.4/3.X/X[B]

If your fingers lining up are the issue this should be a way to figure it out and play the B chord while practicing forming the other shape.
Answer: Slide it, Man!
In your "impossible" transition, I'm assuming you are already fingering an open A chord.  The 2,3 and 4 fingers are in the same position as the B chord, right?  Just two frets down (toward the nut).  So, just leave them in position and "slide" them up to fret 4, then as they come into position plop your index finger for the barre.
This will be a faster version of:

So, when I need to play B major, I first put the fingers 2, 3 and 4 down, and then add finger 1 (bar).

You said this is slow, but maybe it will be faster if you don't even lift up 2,3 and 4, just slide them.  As you slide, start to move the barre finger into position as well.
To Practice:
Finger the Bmaj barre chord on every fret, going up and down, but don't lift up your fingers, just release pressure and slide them around the fret board: B, C, C#, D, E (you are barring the 7th fret on E)...as high as you want to go.  Also slide "down" the fret board until you are on Bb (barre on fret 1), then lift the barre and slide 2,3 and 4 into position, and you have an open A chord!  Practice the transition between open Amaj and Bbmaj (1st fret) barre over and over.
Basically you slide the fingers, which are firmly in position (because you practice and get muscles!) along the top of the strings and just squeeze when you reach the target fret.
EDIT: Advanced Note
As an advanced point, take note that the open A chord and this B chord are the same "form".  That's right, except the nut is functioning as your barre.  As you slide the form up and down the neck, you change key but keep the voicing, or form.  The form is "A" in the C-A-G-E-D school of thinking, named after the open chord.  So what I am really asking you to do is to practice your open "A" form all over the fret board.
Comment: This idea can work, although as a teacher, I find a lot of students can sustain the fingering up to about fret 5/6. After that, fat fingers dictate using just two across strings 2,3,4. Round about fret 8/9 I start to use only my ring finger across 2,3 and 4, as even two don't fit well. So - same strings fretted for the 'A' shape, but not necessarily same fingers everywhere!
Answer: The root of the problem is probably your overall left hand position. The A-shape barre chords need quite a lot of pronation to get the fingers all "in line". By far the easiest setting to achieve this is a proper classical guitar position, i.e. with the arm reaching towards the guitar neck in almost a right angle from below. Buy a footrest and try it the classical way, you may be surprised how much easier it gets.
Of course it's also possible to play such chords in less upright position, but the more you approach a "broomstick grip" on the neck, the harder it gets. Make sure your hand is always nice and loose, never cramped, and that it's flexible enough to rotate so those three fingers can reach their positions.
Answer: Learning to quickly form certain chords often takes an abundant amount of repetitive practice.  There is not really a magic order of finger placement to make the chord in question easier to form quickly.
The chord you describe is commonly referred to as an "A shaped barre chord".  That chord shape is form of "movable" barre chord that can be used to play 12 or more chords (more if you have a cutaway on your guitar body).  It is a good chord to have in your arsenal.
I think the order you are placing your fingers is the most practical way to quickly form the "A shaped" B chord the way you are trying to play it.  If you place your barring finger first, then you must stretch to reach the rest of the chord and to me that makes it harder to maintain the alignment of the other  three fingers (which ideally should hit the fourth fret simultaneously).
You might try practicing just placing the three fingers on the 4th fret until you can quickly form that shape.  Adding the barre finger once you master the hard part should not be difficult at all.  Start by just forming and releasing the chord over and over until you can do it quickly.  Then practice the chord change between A and B until you can do it quickly.
This may not be something that you master in a short period of time.  Just make practicing forming the A shaped barre chord part of your regular practice routine and spend a certain amount of time on it during every guitar practice session.  Eventually you will develop the speed and it will become natural.
Having said that, I personally found it much easier to learn to quickly form the A shaped barre chord by playing it with two fingers instead of four.  I barre with my first finger and use my ring finger to form a mini barre to fret the three middle strings.  You just curve your finger up at the last knuckle to avoid contacting the high e string.
This answer Playing B chord with mini barre shows a picture and offers more detail on how to play the A shaped barre chord "the easy way" (using only two fingers) .  You too may find this easier and faster - but it will still take practice to master this technique.
In my case it took less time to learn this form of playing the A shaped barre chord than trying to play it with four fingers. At first it might not be easy to get your finger to bend that way - but keep practicing.  Perhaps you could keep practicing both ways and see which one you master first. Either way, you will eventually master the A shaped barre chord (using either the four finger fingering or the two finger fingering) with practice practice practice!
Mastering this versatile chord (regardless of your preferred fingering) is worth the time. Good luck!
Answer: With time and practice, everything gets easier. Consider just playing the best you can for now, so that you don't stunt creativity by slowing progress while trying to be perfect. As you get more comfortable with playing in general, you'll find it easy some day to add it in the extra notes.
Answer: The way I do 5th string barre major chords, I barre with the side of the index finger (instead of the flat part like normal barre chords) so I can reach the other notes. Your index finger cannot stretch while being straight - It has to be angled.
You should also always check to see if your normal barre (Just index finger) doesn't mute any strings. If it does, just play with it a bit until you manage it!
Answer: Go from barring the 1st fret of the F ('lead' with your lower fingers -- make getting them to their target your main goal and landing the barring finger a secondary goal) to barring the 2nd fret for the B.
In addition to the barring finger, use your ring finger -- let it bend back at the first knuckle so that it flattens across for the 3 notes on the 4th fret.
If your fingers aren't too strong or your guitar is hard to fret in this way (some of mine have been), try to practice a strong grip.  If you're gripping hard to make the F sound, you may need to practice releasing and quickly gripping again in the B position.
Some of this seems more difficult at first but gets easier as you practice it.  With time your hand muscles strengthen and your neurons make new connections which facilitate finding positions comfortably.
Answer: I have the same problem.  In Fernando Sor's study in Em (Op. 35, No. 24), the tempo is quarter note=88, and the passage is as follows (the b-chord is in the second measure):

If I place the d#, b, and f# fingers first, I can add the b note.  But since the b note is played first, and the tempo is 88, I place the b no problem, but I can never nail the other 3 fingers correctly in time to play the passage.  It sounds like: b buzz buzz buzz!
Answer: You can also try half positions. Instead of using your I-M-A fingers for the left hand use the M-I and pinky. This will allow you to lock your hands and just slide the wholly affair down as you like.
The economy of movement is much better like this and you get the added benefit of training your less intelligent left hand fingers (Looking at you pinky)
Hope that helps.
Comment: This answer is very difficult to understand. Is it different from the [answer](http://music.stackexchange.com/a/33043/3032) by Wilbur Whateley? If yes, please explain what you mean by "half positions", "using I-M-A fingers for the left hand" (how?), "use the M-I and pinky" (how?), "lock your hands", "slide ... down".
Comment: To add to what @anatolyg was saying, I, M and A are traditionally used to refer to right-hand fingers in classical playing (PIMA), so that's confusing here.
Comment: Instead of using you index,  middle and Annular fingers to strum the A chord you use your Middle, Annular and pinky. for the left hand.
This leaves your index open to bar up and down the neck as you wish. And yes the proper term for this is HALF POSITIONS!


Please deconstruct a user agent string for me

Question: Okay I give up. Given the user agent string below, which browser is being used? It might be IE8, since I can't envision firefox sending this. If it is IE8, why the hell is the "Mozilla" string in there? I am not familiar with the history or taxonomy of this stuff. Also, from whence does the string "OfficeLiveConnector" arise? I am not familiar with this product.

Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 5.1; Trident/4.0; .NET
  CLR 1.1.4322; .NET CLR 2.0.50727; OfficeLiveConnector.1.3;
  OfficeLivePatch.0.0; .NET CLR 3.0.4506.2152; .NET CLR 3.5.30729;
  .NET4.0C; .NET4.0E; BRI/2)
Comment: Throw it in here and have a read http://www.useragentstring.com
Answer: A long time ago in an Internet far far away, Netscape (aka Mozilla) was the standards leader.  It sent Mozilla (etc) as the browser string.  Poor IE didn't send Mozilla, so web servers said 'No, you're not supported, go away'.  So, IE (and everyone else) starting sending Mozilla in the beginning of the browser string because it eventually did support all of the special HTML, and then more additional information later on in the browser string.  And now it's 2012 and that's just the way it is.
Short version: Almost everyone sends Mozilla first and then more specific user agent material later.  The additional things are because Microsoft feels like putting in additional information (which .NET libraries we support, etc) which are more properly handled in different ways these days... but that's what the state has evolved to.
Answer: Well, the Mozilla part of the line has more to do with a history of Internet standards and Netscape "back in the day," but that is MSIE 8. Office Live is a Microsoft product that uses IE.
The Internet Explorer User-Agent string on MSDN


What path to images to use with CKEditor to insert images in content?

Question: When putting images in content items, I have to put the full URL, otherwise images don't show up.
It works for this full path:
http://localhost/IT/sites/default/files/mypictures/apache_pb.png

But doesn't work for this path:
sites/default/files/mypictures/apache_pb.png

I know I must be missing something? A token? Variable to path?
Answer: You are missing the forward slash: /sites/default/files/mypictures/apache_pb.png
Incidentally, IMCE will make this easier for you.


How do I properly use the length function in haskell?

Question: I am currently working on trying to find the number of primes between a range in haskell.  The program prints out the range of primes correctly. E.g countPrimesUntil 2 10 will print out [2, 3, 5, 7].  I am looking for the number 4 because that's how many primes is between 2 and 10.  How do I incorporate countPrimes correctly?
import Data.List

countPrimesUntil :: Integral a=> a -> a -> [a]
countPrimesUntil a b = takeWhile (<= b) $ dropWhile (< a) $ sieve [2..]
    while sieve (n:ns) = n:sieve [m | m <- ns, m `mod` n /= 0]

countPrimes n = length([x | x <- [2..n], countPrimesUntil x])

Comment: `while` should be `where`
Answer: countPrimesUntil is misnamed; it doesn't count anything. Rather, it produces a list of primes between a and b, inclusive.
All you need to do is apply length to the result of countPrimesUntil, when given arguments 2 and n.
countPrimes n = length (countPrimesUntil 2 n)
-- countPrimes = length . countPrimesUntil 2

Answer: In that case the countPrimes calls countPrimesUntil 2 n, and determines it length, so:
countPrimes n = length (countPrimesUntil 2 n)


Let $A$, $B$ and $C$ are the vertices of an equilateral triangle and lies on the parabola $y^2=4ax$

Question: Let $A$, $B$ and $C$ are the vertices of an equilateral triangle and lies on the parabola $y^2=4ax$ where $A$ is the vertex of parabola.  Find the side length of triangle.
My attempt :

Slope of line $AB=\dfrac {2}{t}$ where $t$ is a parameter. So,
$$\tan (30)=\dfrac {2}{t}$$
$$\dfrac {1}{\sqrt {3}}=\dfrac {2}{t}$$
$$t=2\sqrt {3}$$
Answer: 1)Equation of line $AB$:
$y=(√3/3)x$; where  $m =\tan 30° =√3/3.$
2) Intersection with parabola $y^2=4ax:$
$y^2= 4a(3/√3)y;$
2 solutions: $y=0$, and
$y= 4a(3/√3)= (12a)/√3.$
Corresponding to $x=0$ and :
$x = (3/√3)((12a)/√3)= 12a.$
Length of a side of the equilateral $\triangle ABC$:
Length $BC:$  $(24a)/√3.$
Check: Length $AB:$
$\sqrt{(12a)/√3)^2 + (12a)^2}=$
$12a\sqrt{1/3+1}= (24a)/√3.$
Comment: amd..A typo: should be BC, as you suggest.Thanks.


Complex known string matching in JS using Regex

Question: I'm working on a name replacement script for an online TTRPG platform, but I am very poor at Regex.
Currently I have the following code which replaces the name correctly in many instances:
el.innerHTML = el.innerHTML.replace(new RegExp("\\b" + data.alias + "\\b", "gi"), replacement);

In this example:
data.alias is the name of the "creature", this could be as simple as something like Bandit or as complex as something like Goblin King (Variant 1).
replacement is a user selected string such as Unknown Creature
A sample el might look something like:

Bandit

or it might be:

The Goblin King (Variant 1) is known to lair in the dank, dark cave

The following problems are causing me grief trying to find the correct matching pattern:
 1. For a common-word name like bandit I do not want the pattern to match a word such as banditry
 2. For names that have non-word characters (such as () my current word-boundary match fails. I'm not certain if simply escaping all special characters is a smart choice
Is there a pattern that can match names accurately given that the name is a known quantity?
Comment: I'm not sure I understand--you're replacing a known explicit string, why can't you just use `replace` with that string?
Comment: Ultimately this will be fairly difficult if you have unbounded input, e.g., "The Bandit, being a bandit, started doing Bandit-like things." Unless you have known boundaries a naive search-and-replace will likely have unintended side-effects almost no matter what.
Comment: @DaveNewton the `replace` function only replaces a single instance of a string unless you use a regex version of the string with a `g` global tag
Comment: @errational what is the purpose of the `"\\b"` at the beginning and end of your Regex?
Comment: @ChrisSandvik I've been through many iterations on this, but I believe it was to remove the "banditry" for "bandit" scenario. I'm assuming you know what it means in RegEx terms, but in case it's unclear it defines a word or string boundary.
Comment: @ChrisSandvik Yes. Without knowing any context there's no way to know if the string may appear multiple times, though.
Comment: @DaveNewton I just assumed that he wanted to match all because he used the global tag in his example
Comment: @DaveNewton "Fairly difficult" as in "not worth the effort to implement"? At this point I'll probably just stick with what I've got.
Comment: @errational Depends on your requirements and the actual data you're dealing with. It's contextually-dependent replacement if you need exact results; it's tricky. If you can relax your expected output, or have a better way to retrieve the data so you don't have that problem it may be doable.
Answer: It should be possible to do this if you use negative lookahead and lookbehind instead of word boundaries. You will, however, need to escape special regex characters such as the parentheses in Goblin King (Variant 1).
Give this a try:
el.innerHTML = el.innerHTML.replace(new RegExp("(?![^\\s,.!?;:])" + data.alias + "(?<![^\\s,.!?;:])", "gi"), replacement);
Demos: https://regex101.com/r/xlvAdt/1 https://regex101.com/r/zvHL1q/1
Basically, the pattern says to look for the given string as long as it's not preceded or followed by anything that isn't a whitespace character or punctuation.
Comment: This is getting very close! I played around and what I think I want instead is a negative **word** lookahead. That way `bandit` would match `bandit,` or `bandit.` but not `banditry`. I'm guessing the simplest way to escape special chars in my target string is just to do a replace on them specifically before passing to the actual regex statement?
Comment: Oh, I didn't realize you had to deal with punctuation. I'll edit the answer to account for this.
Comment: OK I think I have a plan. It's not perfect, but I think it's getting better. Here's my example: https://regex101.com/r/xlvAdt/5
Basically in my JS I will break up any names with spaces into component groups then do a cascading match on the groups


ref qualifier gives error in gcc4.7.2 and vc10

Question: consider the below minimal example.
#include<iostream>

struct A
{
    A(){std::cout<<"def"<<'\n';}
    void foo()&{std::cout<<"called on lvalue"<<'\n';}
};

int main()
{
    A a;
    a.foo();
    A().foo();
    return 0;
}

this gives error about expecting ';' at the end of declaration and and expected un-qualified-id before '{'.
Can i know what i'm doing wrong? in the actual code i want to avoid calling the non-static member function through temporaries.
tried on gcc 4.7.2 and vc2010.
Thanks.
Answer: The answer will be short: VC10 and GCC 4.7.2 do not support ref-qualifiers.
However, notice that your foo() function has an lvalue ref qualifier, meaning that you cannot invoke it on temporaries.
If you want this expression to compile as well:
A().foo();

Then you should use const&, or provide an overload for &&, as in this live example.
To work with ref-qualifiers you can use Clang 3.2 or GCC 4.8.1.
Comment: btw gcc 4.8.1 was just released and is the 1st compiler to support them (clang 3.3 is due next week and will support them)
Comment: oh my god! so quick to answer:-). which version of either supports this?
Comment: @andy as for your edit, thats what i was intending. not to call non-static member functions through temporaries.
Comment: @Koushik: Oh, all right then :) I edited the answer again, just to provide a more meaningful live example
Comment: @AndyProwl Thank you. waiting to accept the answer.:-) by the way know how to which features are supported and not in gcc?
Comment: @Koushik: GCC 4.8.1 is feature-complete :)
Comment: @Guillaume: Actually, Clang supports ref-qualifiers since version 2.9 if remember correctly ;)
Comment: @AndyProwl will update my compiler. clang is more efficient than gcc is it? heard some rumors so?
Comment: @Koushik: I can't really tell, although my experience is that Clang tends to be correct in most situations - but then again, take this with a grain of salt. I'd suggest you trying both.
Comment: @Koushik clang has a nice support for the c++ language.  Its optimizer has still some way to go.  For production (C++) code, I'd recommend g++.
Comment: @Guillaume is it that you suggest g++ and not clang for production code based on optimizer or is there some other reason?
Comment: @Koushik gcc is definitely more mature.  C++ in particular is not what clang supports the best (it would be a totally different story if you were doing Objective C).  I've tried every release of clang so far and it's always been slower for my benchmarks.  But apparently, this is changing with the next release:
http://www.phoronix.com/scan.php?page=article&item=llvm_clang33_3way#=1
Comment: @Guillaume thank you very much. i'm also accustomed to gcc but will download clang too. i might need it when i'm debugging some code and in general.:)


Cannot Return Custom HTTP Error Details Remotely

Question: This is a strange one. I'm running MVC 3 and have a custom action result that wraps exceptions and returns a message along with the standard HTTP error.
public class ExceptionResult : ActionResult
{
    private readonly Exception _exception;

    public ExceptionResult(Exception exception)
    {
        _exception = exception;
    }

    public override void ExecuteResult(ControllerContext context)
    {
        var response = context.HttpContext.Response;
        response.ClearHeaders();
        response.Cache.SetNoStore();
        response.ContentType = ContentType.Json;

        var baseEx = _exception as BaseException ?? new ServerException(_exception);

        var result = baseEx.GetResult();

        var json = result.ToJSON();
        response.Write(json);
        response.StatusCode = (int)result.Status.Code;
    }
}

When I run this locally I get exactly what I expect:
HTTP/1.1 400 Bad Request
Cache-Control: no-store
Content-Type: application/json; charset=utf-8
Server: Microsoft-IIS/7.5
X-AspNet-Version: 4.0.30319
Date: Thu, 01 Dec 2011 19:00:03 GMT
Content-Length: 81

{"error":"invalid_request","error_description":"Parameter grant_type is missing"}

But when I try to connect from a different machine I get the standard IIS error message instead:
HTTP/1.1 400 Bad Request
Cache-Control: no-store
Content-Type: text/html
Server: Microsoft-IIS/7.5
X-AspNet-Version: 4.0.30319
Date: Thu, 01 Dec 2011 19:02:33 GMT
Content-Length: 11

Bad Request

UPDATE
There must be some http module somewhere in the IIS pipeline that is swallowing the response and rewriting the content. I wrote a module to log the request and response and it's returning exactly what I expect however what actually makes it to the browser is wrong.
2011-12-02 15:39:00,518 - ======== Request ========
2011-12-02 15:39:00,518 - GET /oauth/2/token HTTP/1.1
2011-12-02 15:39:00,519 - Cache-Control: max-age=0
2011-12-02 15:39:00,519 - Connection: keep-alive
2011-12-02 15:39:00,519 - Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
2011-12-02 15:39:00,519 - Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.3
2011-12-02 15:39:00,519 - Accept-Encoding: gzip,deflate,sdch
2011-12-02 15:39:00,519 - Accept-Language: en-US,en;q=0.8
2011-12-02 15:39:00,519 - Host: micah-pc:8095
2011-12-02 15:39:00,519 - User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/535.2 (KHTML, like Gecko) Chrome/15.0.874.121 Safari/535.2
2011-12-02 15:39:00,519 - =========================
2011-12-02 15:39:00,519 - OAuth exception occurred.
BoomTown.OAuth.OAuthException: Parameter grant_type is missing
   at BoomTown.OAuth.Request.TokenRequest.GetRequestValidator() in C:\code\BoomTown\Api\BoomTown.OAuth\Request\TokenRequest.cs:line 19
   at BoomTown.OAuth.Request.OAuthRequestBase.Validate() in C:\code\BoomTown\Api\BoomTown.OAuth\Request\OAuthRequestBase.cs:line 33
   at BoomTown.OAuth.Request.OAuthRequestBase..ctor(HttpRequestBase request, IOAuthServiceLocator serviceLocator) in C:\code\BoomTown\Api\BoomTown.OAuth\Request\OAuthRequestBase.cs:line 28
   at BoomTown.OAuth.Request.TokenRequest..ctor(HttpRequestBase request, IOAuthServiceLocator serviceLocator) in C:\code\BoomTown\Api\BoomTown.OAuth\Request\TokenRequest.cs:line 13
   at BoomTown.Api.Web.Controllers.OAuth.V2.OAuthController.Token() in C:\code\BoomTown\Api\BoomTown.Api.Web\Controllers\OAuth\V2\OAuthController.cs:line 26
2011-12-02 15:39:00,520 - ======= Response =======
2011-12-02 15:39:00,520 - HTTP/1.1 400 Bad Request
2011-12-02 15:39:00,520 - Cache-Control: no-store
2011-12-02 15:39:00,520 - X-AspNet-Version: 4.0.30319
2011-12-02 15:39:00,520 - Content-Type: application/json; charset=utf-8
2011-12-02 15:39:00,520 - {"error":"invalid_request","error_description":"Parameter grant_type is missing"}

SOLUTION
Thanks to a little sleuthing I was able to figure it out. I setup IIS tracing which confirmed my suspicions that it was related to the customerrormodule which was intercepting my requests and overwriting my error messages. I kept monkeying with the
<system.web>
  <customErrors />
<system.web>

settings but to no avail. I was on the right track, but since it's IIS 7 that I'm running I needed to change the correct web.config section like this:
  <system.webServer>
    <httpErrors errorMode="Detailed" />
  </system.webServer>

Now all my custom JSON messages come through perfectly. Big thanks to Jason Finneyfrock for the tag team on this one.
Comment: +1 Good question, have you confirmed you are returning the result or is IIS intercepting?  I noticed the Content-Type is different on the remote response.
Answer: In your web.config, do you have httpErrors defined to only be DetailedLocalOnly?  I'm not sure whether or not the content would be removed in this situation.
http://www.iis.net/ConfigReference/system.webServer/httpErrors
Comment: HA! I just figured it out right before seeing this. It's exactly the problem.
Answer: I came across this, not sure if it will help:
context.HttpContext.Response.TrySkipIisCustomErrors = true;


How do I add my new Paragraph type to a content type?

Question: I've made a new Paragraph type and it appears as an option in the Basic Page content type, but I'd also like it to appear in another content type.
Would anyone know where I set this?
Answer: Turns out I was missing a step:

Structure>>Content Types
Edit the content type you want to add the Paragraph to
Go to Manage Fields tab
Find the Paragraphs entry in the list and click edit
Check your bundle from the list


How to replace only SOME missing data

Question: I have two types of missing data (non-responses and "Don't know or does not apply") and I want to replace only the non-responses (with mean or by using EM or by using Multiple Imputation) and to see if this is a good solution. How can this be done in SPSS? Even in the simplest case, when replacing missing values with mean for example, I can't find a way to impute only some of the missing data, in this case the non-responses?
Answer: The easiest solution to your problem is to not to treat "don't know" as missing but a separate data type in itself. By this I mean if you currently have 3 categories, with NA, make it four categories and NA where category 4 is "don't know". After this you can use the standard EM methods
There are 2 points I want to make in connection with @Rociante's reply.
1) I think he/she means f(i) = 0.5*(f(i-1) + f(i+1)). I would not recommend taking the average of the previous and the next in general because a) you do not know that consecutive points are related and b) you seem to have categorical types in which case this does not make sense anyways. If you must, use the MLE estimate.
2) Be very careful while dealing with NULLs in different langauges. Go through the documentation carefully when implementing the pseudo-code. You cannot say for example i=='NULL' in python and in fact most languages will not allow it (not sure of SPSS). Most languages treat NULL as its own type which can be anything. In python you would say
try:
i = i + 0

except:
and in R you could use is.na(..)
Comment: By making "Don't know/Does not apply" a category in itself, do you mean to assign a numeric value to this type of answers and then use it in EM (so to impute also with "Don't know/Does not apply")? Wouldn't the results differ depending on the value that I would assing?
Comment: Depends on how the other categories are assigned. If the value you assign to the "don't know" entry is simply a LABEL and does not hold any numerical significance it will impute values as 1/2/3/"don't know". Make sure you chose the right type of EM imputation technique
Comment: Thank you for your answer! Unfortunatelly, it seems that it is not possible to assing just a label and not a numerical value as well for "Don't know", as long as a variable is defined as numeric (in SPSS).
Comment: Im sorry, I have not worked in SPSS before though I will be very surprised if SPSS does not have that option. Check things having the keyword factor in it. For R the command would as be as.factor
Comment: Maybe it has but so far I wasn't able to find it. Could you be more specific about the keyword "factor"? Where should I look for it? I think it's easier to treat "Do not know/Does not apply" as missing data than as another category.
Answer: I am going to generalize my response instead of making it SPSS-specific (as that's probably against the forum rules). You need to write a loop that goes through your data set. This loop goes through all the values in your data set and replaces the null with the average of the values that come immediately before(i-1) and immediately after (i+1) the null (i.e. non-response). If your data set is small enough, you can also do the calculation manually instead of writing the loop. The pseudo-code is:
for (i=2:n)
{
  if(i=="null")
  {
   i = ((i-1)+(i+1))/2
  }
  else
  {
    i++
  }
}

Comment: Thank you for your answer! But I do not know how to write code. Are you suggesting that the average is calculated based only on the values thae are just before and after the non-response? I have some scales with different items and I need to impute with the average resulted at the level of each item. Thank you!
Comment: The calculation depends on what kind of imputation you want to do. I chose the simplest algorithm of taking the average of the values that flank the missing one because that's the easiest one to illustrate in code rather than MLE. If you want another imputation method that may be more appropriate to your discipline, obviously use that instead of the average. To learn how to write a loop in SPSS specifically, either check the help manual or pose the question on Stackoverflow - they help with programming questions. 1/2
Comment: 2/2  The other option is to do this in R, which has ready-made packages for imputation (not just the simple one I illustrated above).
Comment: Also, I think you need to be careful when you say that the data is missing. If the person said "don't know" or "not apply", then the cell should have some value there, like "n/a" instead of just being blank. In other words, the blank cells should be the only ones that are missing data and for which you want to impute.

How to replace only SOME missing data


Find probability of classification of observations to one of two possible normal distributions

Question: Imagine you start with two relatively large samples of sample sizes 15 and 18 respectively. We can assume they each come from a different normal distribution.
The first (15 observations) comes from distribution A and has a mean 10 and a standard deviation of 3
The second (18 observations) comes from distribution B has a mean 15 and a standard deviation of 3.5
(to be clear, the mean and standard deviations listed above are of observations, not the distributions themselves)
Then you are given a third and a fourth sample (sample C and sample D) of 3 observations each: let's say {12, 11, 8} and {14, 16, 13}
You know that each new sample comes from one of the two distributions and that they both come from different distributions. How do you determine the probability that the sample C comes from distribution A and sample D comes from distribution B and vice versa?
Tries so far: I have written a bootstrapping program that simulates the scenario mentioned 100,000 times, but I would prefer an analytical solution. I have tried using the negative log likelihood of a T distribution similar to the solution mentioned below, but the answers I have gotten are substantially different than what I get in my program.
Comment: This sounds like a homework question. What is the exact phrasing? The idea that immediately came to mind does not answer the question as you've phrased it but does answer a related question. Also, please add the self-study tag, read its wiki, and edit your question to include what you've done so far.
Comment: @dave It's not a homework question. The topic came up organically in some data analysis I'm working on. I wrote the question like this because the actual problem I'm trying to solve is a bit more convoluted, and I wanted to reduce it to its most basic parts.
Comment: Distribution A and B are assumed to have potentially different variance?
Comment: Yes, the observation is that they have different standard deviations
Comment: If the moments of the two normal distributions are known then the initial data is irrelevant --- the problem is solved by a simple application of Bayes' theorem.  Are you sure you intend for the initial data to be irrelevant?
Comment: I'm not sure I understand. The only thing I know about the true distributions is what I have observed from the samples I took. I don't know the true mean or standard deviation of the distributions. I only have the mean and standard deviation of the data.
Answer: One way would be using log likelihood, so the sum of log likelihoods of each unit, in this case obtained from a normal distribution. Computation in R
<code>> -sum(dnorm(c(12,11,8),10,3,log=T))
[1] 6.552652
> -sum(dnorm(c(12,11,8),15,3.5,log=T))
[1] 9.535513
</code>
The goal is to minimize this value so the first case with mean 10 and SD of 3 is a better fit for the new data.
Comment: @JeremyDorner Regarding your edit, the mean and SD are unbiased estimators for the case of normal distributions, so they are your best "guesses" for the population.
Comment: @JeremyDorner Rough estimate `1-(6.552652/(6.552652+9.535513))` to get the probability of belonging in the first population.
Comment: I like the approach, but if I understand correctly, this method does not account for the uncertainty of the mean and standard deviation of the original two samples
Comment: I see. I was looking for the probability that each classification is correct, rather than the most likely classification.
Comment: Ah I got your point. Yeah that correctly answers the question as I asked, but would it still be valid if sample A and sample B have different sample sizes? I am not sure. I have updated the question to reflect this. My bad for not including it originally.


How to get all nodes referencing a particular node?

Question: I have two node types, which I'll call A and B. Type A is a fairly straightforward content type, the only thing special is that it has a field (field_appearances) that references B nodes (tag-style, so each A may have one or more B tagged).
I am using Views to create a nice listing of all my B nodes, and I would like to have each B in this view list the A nodes that are referencing it (basically, so that users can easily see a list of A's that reference that particular B).
Effectively, this should look something like this:

B.1

Used in: A.1, A.2, A.3

B.2

Used in: A.2, A.4

What I've tried
First, I tried setting a relationship Content using field_appearances, then added a Title field to the view that used that relationship. This created a row for each B+A like so:

B.1

Used in: A.1

B.1

Used in: A.2

B.1

Used in: A.3

(...and so on for each B)

Next, I enabled aggregation and tried using various setups to get this right. The closest I got was setting the (referenced) Title field to aggregate on COUNT, which got me the following:

B.1

Used in: 3

B.2

Used in: 2

Any suggestions? I tried dinking around with Contextual filters but didn't get anything close to being right.
Answer: The Relationships and Aggregation features are fairly limited as they directly work on the database query, so you can only aggregate using very simple functions like COUNT, AVG, MAX etc.
What you are trying to do (load multiple related values for each row, and render them together) can be done with a sub-view, for example with this module: https://www.drupal.org/project/views_field_view
That would allow you to create a separate view ("Nodes referencing a particular node") with a contextual filter, then add this view as a field to the main view. It slightly impacts performance, as each row in the parent view executes a new sub-view, but should be okay with caching.


Access a XML file via xslt which is present two level below xslt

Question: location of properties.xml -> web-inf/classes
location of XSLT           -> web-inf/classes/xslt/req/Request.xslt
Properties.xml
    <?xml version="1.0" encoding="UTF-8"?>
    <Properties>
       <UserId>abc</UserId>
       <Password>password</Password>
     </Properties>

XSLT File :
       <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
         <xsl:template match="/">
        <soapenv:Envelope
             xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"
             xmlns:abc="urn:microsoft-dynamics-
             schemas/codeunit/abc_WebService"
             xmlns:any="http://schemas.microsoft.com/BizTalk/2003/Any">
        <soapenv:Header/>
        <soapenv:Body>
            <abc:ImportabcXML>
                <abc:requestXML>
                        <xsl:copy-of select="."/>
                </abc:requestXML>
                <abc:userId><xsl:value-of select="document('/Properties.xml')/Properties/UserId"/></abc:userId>
                <abc:password><xsl:value-of select="document('/Properties.xml')/Properties/Password"/></abc:password>
            </abc:ImportabcXML>
        </soapenv:Body>
    </soapenv:Envelope>
</xsl:template>

I am not able to access the userid and password fields in XML properties file in output I am getting only :
   Current output :
   ....</abc:userId></abc:password>....

    Expected output :
   ....<abc:userId>abc</abc:userId><abc:password>password</abc:password>...

What changes I have to make to document tag so that I can access attributes of Properties.xml present in folder two level below XSLT file?
What I read in one link is location of file to be used by XSLT file should be at same folder level of XSLT. So how can I access the file which is present one level below XSL folder.
Edit : changed one level to two as indicated by Michael.
Answer:
how can I access the file which is present one level below XSL folder.

If your stylesheet is located at:
web-inf/classes/xslt/req/Request.xslt

and the Properties file is at:
web-inf/classes/Properties.xml

then it is not "one level below" but two levels above - and should be accessible using:
document('../../Properties.xml')

Note that XML is case-sensitive: properties.xml is not the same as Properties.xml.
Comment: Thank Michael for answer. But still I am getting sane output   ....... Is there any other problem in code which is preventing to get output :abcpassword.
Comment: Not that I can see.


Linearity of expected value of random vectors

Question: Let $Z_1, Z_2, \ldots, Z_k$ of $Z$ i.i.d. in $\mathbb{R}^n$. A sample mean
\begin{equation}
\bar{Z}_k = \frac{1}{k} \sum_{j=1}^k Z_j
\end{equation}
by the strong law of large numbers is
\begin{equation}
\bar{Z}_k \to x
\end{equation}
almost surely as $k \to \infty$.
The variance of $\bar{Z}_k$ is given by
\begin{equation}
\frac{1}{k^2} \mathbb{E} \left( \left\| \sum_{j=1}^k (Z_j -x ) \right\|_2^2 \right)
\end{equation}
in which cases can obtain the equality?
\begin{equation}
\frac{1}{k^2} \mathbb{E} \left( \left\| \sum_{j=1}^k (Z_j - x ) \right\|_2^2 \right) =
\frac{1}{k^2} \sum_{j=1}^k \mathbb{E} \left\| Z_j - x \right\|_2^2
\end{equation}
Answer: It is true by independence of $Z_j$'s. Note that $Z_i-x, 1\leq i \leq n$ are orthogonal since they have mean $0$ and they are independent. For orthogonal vectors $(v_i)$ we have $\|\sum v_i\|^{2}=\sum \|v_i\|^{2}$.
Comment: How can we relate orthogonality with zero mean? Do we assume mean 0, since $\bar{Z_k} \to x$   almost surely for large enough $k$ ? Can you please elaborate a little more about it?
Comment: If $X$ and $Y$ are independent random vectors with mean $0$ then $E \langle X, Y \rangle=E\sum X_iY_i=\sum EX_iY_i=\sum EX_i EY_i=0$. @Lin


Any way to determine what "configure" parameters were used for current installation of nginx?

Question: I want to upgrade nginx, and I want to use the same ./configure parameters I used the last time (--prefix=..., --conf=..., etc...). If I don't have access to the original installation directory, is there any way to query nginx or any config/cache file that I could use to obtain these parameters? (If not, is there any way to determine what these parameters were if I do have access to the original installation directory?)
Answer: Figures that I spend half an hour researching this, can't find anything, and post a question only to find the answer five minutes later staring at me in the docs: http://wiki.nginx.org/CommandLine

-V Print nginx version, compiler version and configure parameters.

So nginx -V did what I needed.


How to automatically switch to debug mode on a warning?

Question: I want to debug a warning that occurs well into the code's execution.
A simple breakpoint won't do, because the line that results in the warning executes millions of times without warning before the first warning occurs.
Also, the line where this is happening is in library code (more precisely, in pandas/core/common.py), so my preference is not to modify the code at all.
I just want to stop the program's execution right when it emits the warning, and inspect the stack at this point, either with pdb or with ipdb.

Is there a way to configure either debugger to automatically enter single-step mode upon the issuing of a warning?
Comment: Do you mean basically what happens if you insert `import pdb;pdb.set_trace()` at that point?
Comment: @Two-BitAlchemist: yes, pretty much, except that, as I wrote, I don't want to actually modify the code being debugged.
Comment: A warning is a warning, not an exception. The debugger will not pick it up. Usually you either change the code to prevent the warning or your suppress it as described here: https://docs.python.org/2/library/warnings.html . If you need help with a particular warning, just ask!
Answer: You can write a script dbg.py:
import pdb, warnings, sys
import __builtin__

if __name__ == '__main__':
    args, n = [], len(sys.argv)
    if n < 2:
        sys.exit(1)
    elif n > 2:
        args.append(__builtin__.__dict__[sys.argv[2]])
        if n > 3:
            args.append(int(sys.argv[3]))
    warnings.simplefilter('error', *args)  # treat warnings as exceptions
    try:
        execfile(sys.argv[1])
    except:
        pdb.post_mortem(sys.exc_info()[-1])

You can then use it to debug your script like that. Pass in your script name as the first argument if you want to run pdb on any warning:
$ python dbg.py yourscript.py

Pass in warning type as the second argument if you only want pdb to run when some particular type of warning is raised:
$ python dbg.py yourscript.py DeprecationWarning

Line number as the third argument:
$ python dbg.py yourscript.py DeprecationWarning 342

You can also rewrite the code using warnings.filterwarnings instead of warnings.simplefilter to make warnings filtering even more flexible.
Comment: If you try to use this you should be aware that in Python 3 the module `__builtin__` was renamed `builtins`, more info:
https://stackoverflow.com/questions/9047745/where-is-the-builtin-module-in-python3-why-was-it-renamed
Answer: I found the answer offered by @user2683246 elegant and useful. Here is a variant of the solution modified for compatibility with Python3 (tested with Python 3.7):
#!/usr/bin/env python

import pdb, warnings, sys
import builtins

if __name__ == '__main__':
    args, n = [], len(sys.argv)
    if n < 2:
        sys.exit(1)
    elif n > 2:
        args.append(builtins.__dict__[sys.argv[2]])
        if n > 3:
            args.append(int(sys.argv[3]))
    warnings.simplefilter('error', *args)  # treat warnings as exceptions
    try:
        with open(sys.argv[1]) as f:
            code = compile(f.read(), sys.argv[1], 'exec')
            exec(code)
    except:
        pdb.post_mortem(sys.exc_info()[-1])

Notable changes:

Replace the execfile() call with the Python 3 variant; and
Replace __builtin__ with builtins.
Comment: I'm trying to use this with the Pint library, which defines its own warning classes in pint.error.  But when I use names like UnitStrippedWarning I get a KeyError.  How do I tell dbg.py to look at names in the UnitStrippedWarning class that pint defines?
Answer: Instead of treating the warning as error, warnings.catch_warnings link can be used to access warning list and switch execution into PDB session if the scope of code which throws warning can be identified.
However I recommand to start your program with PDB, set a breakpoint to break the execution when detecting warning number change of warning list after the problematic code snippet. You will be benefited if your debugging code snippet is in a loop.
example:
import warnings

with warnings.catch_warnings(record=True) as w:
    warnings.simplefilter('always')
    warningNum = len(w)
    for i in range(someNumber):
        "your code probably throw warning"

        if len(w) != warningNum:
            warningNum = len(w) #set break point here

run script with python -m pdb yourscript.py and set a breakpoint in line warningNum = len(w), then execution can be suspended when detecting warning number change.
Answer:
https://pypi.python.org/pypi/rpdb/

i found rpdb very handy to debug such problem, when you have no control of starting the program. what you need is temporarily modify pandas/core/common.py to add
import rpdb
debugger = rpdb.Rpdb(port=12345)
debugger.set_trace()

when the warning is triggered, the debugger will be there waiting for connection. you then connect to the debugger and inspect the stack.


Multiple path alias for a url

Question: I've installed the pathauto module. I have a content type article. When I'm trying to create an article, the path is created automatically in the form content/article-title, that is fine.
However, I want to pass some dummy values via url like content/article-title/value1, content/article-title/value2. So now I have multiple aliases for the url.  I will create some functionality using this dummy value.
If I try to access node/10/value1, I can access the page. But I want to access with path alias like content/article-title/value1.
How can I access a page using content/article-title/value1, content/article-title/value1 and content/article-title?
I don't need to create multiple path alias for url. But I need to access page using above urls.
Is it possible?
Answer:
Eventually, I got the solution for this. Please refer http://www.phponwebsites.com/2016/08/drupal-7-pathauto-multiple-url-alias.html
Comment: http://data.agaric.com/multiple-aliases-drupal check this
Answer: You need to set path at config >> URL aliases >> patterns under that article patter you need to set something like.
content/[node:title]/[node:field_machine_name]
You can access with pattern url otherwise you can access by default with "node/nid".
Comment: It is not based on field. It is a custom value. I need to pass 2 values like value1 and value2
Comment: which kind of value you want to pass?
Comment: String like sum and non-sum
Comment: just enter in tags for sum or non-sum and use that field in content/[node:title]/[node:field_tag]
Comment: Where to do this? and how?
Comment: At config >> URL aliases >> patterns under the article pattern. While you create new article in tags you can set this term.
Comment: How to set 2 values? There is only one textbox for a atricle
Comment: Let us [continue this discussion in chat](http://chat.stackexchange.com/rooms/29658/discussion-between-vimal-goradiya-and-guru).
Answer: You should consider passing the values as parameters instead of arguments.
Arguments:

content/article-title/value1
content/article-title/value2

Parameters:

content/article-title?key1=[value1]&key2=[value2]

Parameters will mean you can still have a single path alias for your node.
You pick up parameters in your code by looking in the global $_GET variable.
Comment: Yes we could do this but it affects SEO.
Comment: A great deal of how to handle this is going to depend on what you're doing with it.  How do you plan to add the functionality?  Server-side?  Client-side?
Comment: For client side validation
Comment: You will need mutliple aliases for each node then.  I'm not sure pathauto will do that for you but you should be able to write a custom module that adds new items to the aliases settings (`/admin/config/search/path`) using functions from the pathauto module.
Comment: Yes i need to do. Is any other options like while create node?
Comment: If you want to do it programatically, have a look at [hook_node_insert()](https://api.drupal.org/api/drupal/modules!node!node.api.php/function/hook_node_insert/7)
Comment: How to create path alias with custom pattern programmatically?
Comment: http://drupal.stackexchange.com/questions/170356/create-custom-path-alias-when-new-user-is-added-in-drupal-7
Comment: One path can be possible for one node it can't be possible multiple path for one node.
Comment: See other answer - going to delete this one as it doesn't actually answer the question.
Comment: It is the correct solution. But i have to add 2 custom pattern for a content type. If i used hook_pathauto(), i could to use only one pattern
Answer: You will need multiple aliases for the same node.
Create a custom module that uses hook_node_insert() to trigger a function that uses path_save() to add a new alias for the node.
path_save only overwrites paths if you direct it to do so with $path['pid'];

Multiple path alias for a url


Does survivol spaces get garbage collected before moving to the old generation?

Question: I understand that when the Eden is full, a minor garbage collection is done. Surviving objects go to the survivol spaces. These objects will eventually arrive to the old generation.
Does the objects in the survivol spaces get garbage collected as well, or they will just be moved to the tenure generation and be GC there later (so the survivol spaces are no more than buffers for performance reasons)?
In other words, which one of the following algorithms is correct?
NOTE: Let's call YG to the Eden, OG the old generation, SE the survivol space that is (E)mpty at a given time, and SN the one that is (N)ot.

YG is full. Minor GC runs on it and survivors go to SE while objects from SN go to OG.

YG is full. Minor GC runs on it and survivors go to SN first until SN is full, and remaining YG survivors go to SE. SN, which is now full, runs its own GN and its survivors go to OG. If all YG survivors weren't enough to make SN full, all YG survivors go to SN anyway but no GC runs on SN.

YG is full. Minor GC runs on it and SN together (regardless of whether SN is full or not). SN survivors go to OG. YG survivors go to SE.

NOTE: I have assumed that the number of YG survivors is never big enough as to fill SE more than once. What happens if, for instance, the number of YG survivors is twice or more the size of SE?
Answer: I found a documentation that explains it nicely.
The documentation from Oracle (https://www.oracle.com/webfolder/technetwork/Tutorials/obe/java/gc01/index.html) basically shows the same, although I find that documentation confusing because the first two images in the section "The Generational Garbage Collection Process" contain a partially filled survivor space, whereas the third image assumes the process started with two empty survivor spaces.
Some more documentation is at https://docs.oracle.com/javase/8/docs/technotes/guides/vm/gctuning/generations.html and https://docs.oracle.com/javase/8/docs/technotes/guides/vm/gctuning/sizing.html
Please note that naming Eden as YG is misleading - the survivor spaces are also part of the young generation.
Basically the steps are:

Eden is full. Minor GC runs on YG, survivors (from Eden and from SN) go to SE.

Survivors from Eden now have a generation count of 1, survivors from SN have their generation count incremented.

Survivors with a generation count above some threshold are not copied to SE but to the old generation.

What happens if SE is too small?
https://docs.oracle.com/javase/8/docs/technotes/guides/vm/gctuning/sizing.html explains this case:

If survivor spaces are too small, copying collection overflows directly into the tenured generation.

I found no documentation for the following claim, but it seems reasonable that copying into SE starts with live objects from Eden and the live objects from SN are copied last. This way if an overflow occurs chances are that the overflowing objects are from SN (i.e. already older objects that have a higher chance of being promoted anyway.)