Feeds with Xpath Parser won't import images using image URL in XML file

Question: Importing images into a multi-valued image field using image URLs from an XML file is not working for me. The Xpath Parser debug output shows the multiple image URLs being parsed correctly, but the images don't get imported. No problem with other ordinary fields.
The XML structure is:
<units>
  <unit>
    <unit_details>
      <images>
        <image>
          <uri>
             http://www.example.com/files/content/villa-102-1.jpg
          </uri>
        </image>
        <image>
          <uri>
             http://www.example.com/files/content/villa-102-2.jpg
          </uri>
        </image>
      </images>
    </unit_details>
  </unit>
</units>

The context is: //unit
The Xpath query for the image field is: unit_details/images/image/uri
I played around with the image grabber module for feeds, but it failed also - doesn't seem suited to this task.

Is it possible to import images using the image URL from the XML
file?
Is it possible to import multiple images into a multi-valued image field?

I'm using Feeds version 6.x-1.0-beta12+18-dev, and Feeds Xpath Parser version 6.x-1.12

UPDATE:
I was able to import images using the CSV importer and the image URL, so this appears to be a problem with Xpath Parser.

UPDATE 2:
I'm seeing no errors in the dblog or the server log.  That patch is for D7. The images do not show up in the node display, but the other fields do.
Looks like the "enclosure" error gets thrown if the local file name isn't in the right form, but I just have an external URL.  As I mentioned above, the image with the same URL does get imported using the CSV parser, so it doesn't appear to be a problem with the Feeds module, just the Xpath Parser.
The relevant code in D6 (FeedsParser.inc) is:
    /**
       * @return
       *   A path pointing to a file containing the resource referenced by the
       *   enclosure. This method downloads the resource if it is not local. The
       *   file path must be considered temporary and is only valid for the current
       *   page load.
       *
       * @todo Get file extension from mime_type.
       * @todo This is not concurrency safe.
       */
      public function getFile() {
        if (empty($this->file) && $this->getValue()) {
          // Check if this enclosure contains a local file.
          if (!parse_url($this->getValue(), PHP_URL_SCHEME)) {
            if (file_check_location($this->getValue(), file_directory_path()) || file_check_location($this->getValue(), file_directory_temp())) {
              if (file_exists($this->getValue())) {
                $this->file = $this->getValue();
                return $this->file;
              }
            }
            throw new Exception(t('Invalid enclosure %enclosure', array('%enclosure' => $this->getValue())));
          }
          $filename = basename($this->getValue());
          if (module_exists('transliteration')) {
            require_once drupal_get_path('module', 'transliteration') . '/transliteration.inc';
            $filename = transliteration_clean_filename($filename);
          }
          $dest = file_destination(file_directory_temp() .'/'. $filename, FILE_EXISTS_RENAME);
          if (ini_get('allow_url_fopen')) {
            $this->file = copy($this->getValue(), $dest) ? $dest : 0;
          }
          else {
            $this->file = file_save_data($this->getContent(), $dest);
          }
          if ($this->file === 0) {
            throw new Exception(t('Cannot write content to %dest', array('%dest' => $dest)));
          }
          $this->delete_file = TRUE;
        }
        return $this->file;
      }

}

Answer:
yes it's possible.
Feeds is buggy sometimes.

Try this patch:
http://drupal.org/node/1482530
Can you give more information about what isn't working? What errors are produced etc.
Comment: Tried this in D7 and it throws the error: "Download of http://www.example.com/files/content/en-thailand-villa-102-1.jpg failed with code -1002." I can't find what component is responsible for that error code. cURL doesn't seem to have error codes like that.  Tried forcing Feeds NOT to use cURL but it still fails. Think I'll file a bug report. D7 Feeds is still Alpha code, but the problem is likely the same as in D6.  Puzzling though since importing the same URL using the CSV parser works ok.
Comment: Hmm, can't put all the code in comments - have to edit original post again.
Comment: Might have something to do with permissions of your tmp directory.
Comment: Can't be permissions since the CSV parser works ok with Feeds.  Anyway, /tmp perms are 777.
Comment: @Jeff I am facing the same issue with xpath parser. Are you able to get around this problem of images? It has been more than a year now.


Keyboard shortcut to jump to closing curly brace or square bracket in json view in Notepad++?

Question: I am using the JSONViewer plugin in Notepad++ and viewing many large and nested json elements in a file. What keyboard shortcuts can I use to jump to a } or ]? This would be similar to Visual Studio's CTRL+].
Answer: Place your cursor on the { and then type :
Ctrl+B
Notepad shortcuts
Comment: The only downside here: it does NOT work dynamically in a recorded macro (Notepad++'s built-in macro recording/playback feature).  It will be treated as a "# of characters navigation", i.e. if your bracket/brace was 10 characters ago, you record this action, then you try to replay it on another line where the brackets are 20 characters apart, the replayed macro will only navigate by 10 characters.  =(   There's no solution to this, and it's not what the OP asked, but I thought it'd be useful for future visitors who use key-shortcuts with macros.
Comment: I wonder if there is a feature that jumps to the start of the PARENT scope instead of switching between the start and end of the scope denoted by the previous open / close brace? Does anyone know?


Restore Deleted Update List SCCM 2007

Question: I mistakenly deleted an large update list from my SCCM 2007 console.  Anyway to restore it?
Answer: Sadly, short of recovering the database from a prior backup... the answer is no (and I do not recommend doing a DB recovery to get your list back).  It would be nice if SCCM gave you a dummy box before it blows away your update list :(
Unfortunately, you'll need to re-create your update list.
Of course, in the future, you can change the permissions on the update list so that you can't delete it.  That way, you'll need to explicitly give yourself delete permissions first, thus giving you an additional step for safety.

Restore Deleted Update List SCCM 2007


How can I re-write feeds xpathparser data?

Question: I have a feed content type with an author(s) field. Some of the nodes have several authors, so I am able to explode the data into an array with feeds tamper. However, I'd also like to re-write the author entries from LAST_NAME, FIRST_NAME to FIRST_NAME LAST_NAME. Before I dive into writing a plugin, I was wondering if there were another option for this, it seems like a common use case.
Answer: You can use the REGEX find/replace plugin in Feeds Tamper to do it.
Find: ([^,]+),\s*([^,]+)
Replace: $2 $1
Note: The above regex is more-or-less a guess and assumes that there are no commas in the FIRST_NAME or LAST_NAME.


MessageDrivenBean: AMQ122000: I''m closing a JMS connection you left open

Question: when sending some messages via a MDB there are some warnings about unclosed JMS connections which then are closed by ActiveMQ.
The MDB gets a messageHandler injected which gets a replysender injected whichs method is given below.
This is the warning I do get:
<code>[org.apache.activemq.artemis.jms.client] (Finalizer) AMQ122000: I''m closing a JMS connection you left open. Please make sure you close all JMS connections explicitly before letting them go out of scope! see stacktrace to find out where it was created: java.lang.Exception
at org.apache.activemq.artemis.jms.client.ActiveMQConnection.<init>(ActiveMQConnection.java:155)
at org.apache.activemq.artemis.jms.client.ActiveMQConnectionFactory.createConnectionInternal(ActiveMQConnectionFactory.java:750)
at org.apache.activemq.artemis.jms.client.ActiveMQConnectionFactory.createConnection(ActiveMQConnectionFactory.java:233)
at org.apache.activemq.artemis.jms.client.ActiveMQConnectionFactory.createConnection(ActiveMQConnectionFactory.java:229)
[...]
</code>
The warning occurs (not every time) within the following code when the try-block has finished (so directly after log.debug(..)):
<code>    private Message doSendAndReturn(XmlMessageCreator messageCreator) throws JMSException {
    Message message = null;
    try (Session session = cf.createConnection().createSession(false, Session.AUTO_ACKNOWLEDGE);) {
        MessageProducer producer = session.createProducer(jmsReplyQueue);
        message = messageCreator.createMessage(session);

        producer.send(message);
        log.debug("JMSTemplate sended message to myEnvironment with ID "
                + message.getJMSMessageID()
                + "\n Using Thread "
                + Thread.currentThread().getName());
    }
    return message;
}
</code>
I still read that these warnings also occur when theres no reference to the connection factory but "cf" is a global singleton variable which is defined via the context:
<code>    @Resource(lookup = "java:/myProject_myEnvironment_factory")
private ConnectionFactory cf;
</code>
When setting a break-point on log.debug(...) I can see that it seems to work some times but sometimes not. This method is called about 7 times while the first three times work, then one time throws the warning four times (probably also for every previous call) and so on for a few times.
This is reproducable every time I do a specific task within the webapp.
I do not know whats going wrong here.
Any advice would be grateful. Thanks in advance.
Answer: I think the problem is that although the session object is defined in the try-with-resource part but there is no explicit variable for the connection within the try-with-resource part.
After changing it from:
<code> try (Session session = cf.createConnection().createSession(false, Session.AUTO_ACKNOWLEDGE);) {
</code>
to:
<code> try (
            Connection connection = cf.createConnection();
            Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
        ) {
</code>
I am not getting the warnings any more.
Thanks for listening.


Why does Drush require sudo?

Question: I'm running Ubuntu 14.04.5 with Drush v 8.1.8 and I can't seem to execute Drush without using sudo. For example if I try to execute 'drush cc all' without sudo, I get:
'Directory /home/myuser/.drush/cache/default exists, but is not writable. Please check directory permissions. '
'Directory /home/myuser/.drush/cache/complete exists, but is not writable. Please check directory permissions.   '
If I then manually modify the permissions on .drush and everything under it to 777, the next Drush command will work but the one after that will fail with the same error. I also tried 'chown -R myuser:myuser ~/.drush'.  Same result.
I thought perhaps I installed Drush incorrectly, so I tried removing and then re-installing it three different ways:

Using this approach: https://www.drupal.org/node/1248790 (sudu apt-get install drush).
This way: http://docs.drush.org/en/master/install/ (executing php to load Drush from a remote file)
Finally by installing Drush using method (2) and then moving Drush into my home/bin folder and chown -R to me.

All of them have the same result — drush doesn't work without sudo. There's no reason I can think of why this should be. What's even weirder is if I chown of .drush (and everything under it) to me, then execute drush without sudo, it will change ownership of directories under .drush/cache to root. I don't even know how that's possible since I'm not root!
Please let me know how I can get Drush to work without root privileges.
Thanks.
Comment: _I chown of .drush (and everything under it) and  to me, then execute drush without sudo, it will change ownership of directories under .drush/cache to root._ That's a mis-configuration or bug in your OS. Drush is like any bit of software, it can't escalate the privileges of the executing user unless the OS lets it. I can't imagine drush would try to do that either, it wouldn't serve its purpose in any way. Just for the record, been using drush for 6+ years in D6/7/8, I've never needed to use sudo on any platform even once to run a command. Try installing in an empty VM to sanity check
Comment: Maybe you have installed drush using sudo or root?
Comment: Andrew, I had to install Drush as root because it installs in /usr/bin. And /usr/bin requires root privileges to install in. Isn't that how it should work?
Answer: I'd suggest you follow the official install instructions here after removing your current install - http://docs.drush.org/en/master/install/
When you have it installed then navigate to your home folder:
cd ~/
ls -lash

At this point your .drush folder should have your user as owner (not root)
If it doesn't then run
sudo chown myusergoeshere:myusergoeshere .drush -R

You can run ls -lash again and confirm the right user and group.
You should now be able to run drush without using sudo.

The reason you get that error is because when you installed it the system created the folder using the root user in your home directory so as your user you don't have permission to modify the folder.

Why does Drush require sudo?


How to obtain metric on Minkowski space from given coordinates?

Question: I am given coordinates on the Minkowski space:
$Z_{0}=\frac{t^2-r^2-l^2}{2t}$,
$Z_{i}=l\frac{x_{i}}{t}$ with $i=1,2,3$,
$Z_{4}=\frac{t^2-r^2-l^2}{2t}$
where we have $r^2=x_{1}^2+x_{2}^2+x_{3}^2$.
Now I am wondering how to verify that for the metric we have:
$ds^2=\frac{l^2}{t^2}(-dt^2+dx_{1}^2+dx_{2}^2+dx_{3}^2+dx_{4}^2)$.
All I have been able to calculate is that we have $-Z_{0}^2+\sum_{i=1}^{4}Z_{i}^2=\frac{l^2\cdot r^2}{t^2}$.
Furthermore I know that we are able to represent the metric by a matrix:
$g_{\mu \nu}=\frac{l^2}{t^2} diag(-1,1,1,1,1)$, but sadly I do not have an idea how to verify the form above...
I am thankful for every answer and comment you leave!
Thank you in advance!
Answer: The Minkowski metric is given by $-dZ_0^2 + \sum_{i=1}^4 dZ_i^2$. We want to pull this back by the parametrization you've supplied. (I'm assuming that $l$ is constant.) Well,
\begin{align*}
dZ_0 &= \frac12(1-\frac{l^2}{t^2})dt - \frac1t(x_1\,dx_1+x_2\,dx_2+x_3\,dx_3) \\
dZ_i &= l\left(-\frac{x_i}{t^2}dt + \frac1t\,dx_i\right), \quad i=1,2,3 \\
dZ_4 &= dZ_0
\end{align*}
So, of course, when we calculate the pullback, $-dZ_0^2 + dZ_4^2 = 0$, and we're left with
$$\sum_{i=1}^3 dZ_i^2 = l^2\left(\frac{r^2}{t^4}dt^2 + \frac1{t^2}\sum_{i=1}^3 dx_i^2-\frac{x_i(dt\,dx_i + dx_i\,dt)}{t^3}\right).$$
I'm assuming there's an error in your question. In particular, how can $dx_4$ appear? Is it possible that $r^2 = x_1^2+\dots+x_4^2$? I also think that if you're talking about "half of Minkowski space," you certainly cannot have $Z_0=Z_4$. Indeed, what do you even mean by this phrase? Please double-check everything.
Comment: First of all thank you very much! In fact sorry for the confused way I posed my question. In the source I'm referring to we have r^2=x^2+y^2+z^2 as I said, but I see the problem you're pointing out.
Comment: Do you have a clou how the desired form $ds^2=\frac{l^2}{t^2}(-dt^2+dx^2+dy^2+dz^2)$ can be recieved, even though there might be a mistake or confusing error in the question setting (for which I am very sorry!) ?


LiteDB - Selecting multiple entries with one id

Question: Okay, apologies if the title is misleading, I couldn't find the right wording for it.
So I have a collection from which I want to count all entries with UserId where the StatusId is a value.
I'm looking for something similar/the same as the SQL query below.
SELECT COUNT(*) FROM Warns WHERE UserId = uId AND StatusId = sId;
Does something like that exist for LiteDB?
Comment: Have you bothered checking/reading the LiteDB documentation? (https://github.com/mbdavid/LiteDB/wiki/Queries)
Answer: You can use the Count method directly:
var count = collection.Count(Query.EQ("Field", "Value"));

Or use the standard collection methods:
var count = query.Run(...).LongCount();


Converter notação cientifica em decimal

Question: Como eu posso converter um número em notação cientifica como 2.6274846602703e-6 em um número decimal usando somente javascript ?
Answer: Basta fazer a conversão com a função Number() que servirá para qualquer expoente dentro dos limites definidos em Number(). Veja:

var notacao_cientifica = 2.6274846602703e-6;
var string_notacao_cientifica = "2.6274846602703e-6";

var convertido_1 = Number( notacao_cientifica );
console.log( convertido_1 );

var convertido_2 = Number( string_notacao_cientifica );
console.log( convertido_2 )

Uma resposta mais completa, válida para qualquer valor de expoente, é a que se segue comentada mais abaixo. Mas note que o resultado sai como string e, para fazer operações matemáticas básicas, será necessário converter a string para número. E, ao fazê-lo, se ultrapassar o limite máximo definido para números fracionários definidos para a linguagem, haverá aproximação do valor e até mesmo truncagem.
Para realizar tais operações matemáticas básicas em números maiores que ^19 e menores que ^-5 sem que se perca precisão, seria necessário defini-las manualmente. Não é algo fácil de processar com JavaScript, fugindo ao escopo da linguagem e da própria pergunta. Recomendo tentar só para aprendizado.
Para simplesmente mostrar como string, não há problemas. Funciona perfeitamente.

// Glossário
//
// NNC = Número em Notação Científica
// NCE = notação científica de mantissa E
// BASE = obtido de base()
// expoente() = obtém o expoente do número em NCE
// base() = obtém a base do número em NCE
// inteiro() = obtém parte não fracionária da base
// fracao = obtém parte fracionária da base (em números decimais)
// N = número em NCE

// Valores de exemplo
var a = "2.6274846602703e21";
var b = "2.6274846602703e-7";

// Funções de auxílio
var expoente = function(NNC) {
  return (/[e][-0-9]+$/g.exec(NNC)).toString().slice(1);
};
var base = function(NNC) {
  return (/^\d\.\d+/g.exec(NNC)).toString();
};
var inteiro = function(BASE) {
  return base(BASE).slice(0, 1);
};
var fracao = function(BASE) {
  return base(BASE).slice(2);
};

// Converte números em notação científica de mantissa "E" (E = 10) em forma decimal
var conversor_de_nce = function(N) {

  // Declaração de variáveis
  var delta, R;

  // Obtém dados necessários
  var e = Number(expoente(N));
  var b = base(N);
  var i = inteiro(b);
  var f = fracao(b);

  // Caso de expoentes positivos
  if (e >= 0) {

    // Diferença de dígitos entre a parte fracionária e o valor do expoente
    delta = f.length - e;

    return delta > 0 ? i + f.slice(0, e) + "." + f.slice(e) : i + f + "0".repeat(Math.abs(delta));

    // Caso de expoentes negativos
  } else {
    return "0." + "0".repeat(Math.abs(e) - i.length) + i + f;
  }

};

// Exemplos
console.log("número: \t\t" + a);
console.log("conversor_de_nce: \t" + conversor_de_nce(a));

console.log("---");

console.log("número: \t\t" + b);
console.log("conversor_de_nce: \t" + conversor_de_nce(b));
Comment: Discordo, suponha que o número seja: "2.6274846602703e-20"
O que irá ser retornardo: "2.6274846602703e-20"
Comment: @MarceloJunior De fato, erro crasso o meu. Devo alterar com uma resposta mais apropriada e deixar explícito que seja qualquer expoente dentro do máximo permitido.
Answer: Para expoentes não muito pequenos ou muito grandes, uma simples atribuição de valor já resolve o seu problema
let num = 2.6274846602703e-6
console.log(num)
/* 0.0000026274846602703 */

Answer: Você também pode usar o sinal + na frente de sua string para obter um número.

console.log(+2.6274846602703e-6);
console.log(+"2.6274846602703e-6");

Converter notação cientifica em decimal


Can any data be learned using polynomial logistic regression

Question: We know that a Taylor polynomial can approximate any continuous function. As @DemetriPananos noticed, Logistic regression seeks to estimate the coefficients for a model and any cut off is imposed post facto. But suppose there's a best possible decision boundary for our data. By "best possible" I mean a decision boundary that perfectly separates two classes.
Assume, for the sake of simplicity, that there is no data points from positive class that overlay data points from negative class (as @Sycorax suggested). For example consider this plot:

The blue line perfectly separates two classes. But the blue line itself doesn't represent a function.

If we were to increase a degree of polynomial in our logistic regression, can we be sure that such a perfect decision boundary would be found for any data that can be perfectly separated?

If the answer to my first question is "yes", then how to prove (or show) it?
Comment: This answer to an unrelated question includes a picture of a decision boundary constructed by quadratic features. https://stats.stackexchange.com/questions/164048/can-a-random-forest-be-used-for-feature-selection-in-multiple-linear-regression/164068#164068
Comment: This question seems to be based on confusing polynomial functions $p:\mathbb{R}\to\mathbb{R}$ with zeros with polynomial functions $p:\mathbb{R}^2\to\mathbb{R}.$
Comment: $f(x_1, x_2) = (x_1)^2 + (x_2)^2$ is a polynomial, with $f(x_2, x_2) = 1$ forming a decision boundary.
Comment: Perhaps you should [edit] your question to state precisely what you do mean. Your comments describe a scenario involving "any data," but now you've said you're only considering some very specific cases. Even if we go by the pictures you've shared, it's not clear whether or not there are `+` examples "hidden under" the yellow circle examples.
Comment: @jwimberley, Yes, there is a cut off made by $z = 1$ plane. But how to show that for any data can be found such a cut off, provided we use polynomial of high enough degree?
Comment: If you have two observations with the same features $x_i = x_j$ but different labels $y_i \neq y_j$, it is not possible to draw a boundary separating them.
Comment: @Sycorax, Hello! I didn't mean that. Consider pictures in this [question](https://datascience.stackexchange.com/q/21896/126125). If we were to increase the degree of polynomial in logistic regression, would it lead us to decision boundary that can properly separate the data on all the 3 images in the question? If your answer is yes, then why? I mean how to prove it?
Comment: @Could you elaborate a little bit? I can't see where the confusion is.
Comment: "... the blue line itself doesn't represent a function" says it all.  That blue line is the *zero set* of a function.  It is not intended to be the graph of a function.
Comment: @whuber, Yes, the blue line is a cut off made by $z = 0$ plane. But is there a way to show this cut off can be made of any form (provided we use a polynomial of high enough degree) to fit the given data? Do you feel what I mean?
Comment: I think I follow. Let the data consist of two finite disjoint sets $A$ and $B.$ We can always find two disjoint *open* sets $\mathcal A$ and $\mathcal B$ where $A\subset\mathcal A$ and $B\subset\mathcal B$ (take small open balls centered at each data point, *e.g.*). $C=\mathbb{R}^2\setminus(\mathcal A\cup\mathcal B)$ is a closed set not containing any of the data. The function $d_C:\mathbb{R}^2\to\mathbb{R},$ $d_C(x)=$ the distance from $x$ to $C$ is well-defined and continuous. Set $f_C(x)=d_C(x)$ for $x\in \mathcal A$ and $f_C(x)=-d_C(x)$ for $x\in \mathcal B.$ $C$ is the zero set of $f_C.$
Comment: [Perhaps of interest to the OP or readers of this question](https://stats.stackexchange.com/a/546815/247274)
Answer: Comments to the question suggest the following interpretation:

Given any two non-overlapping finite collections of points $A$ and $B$ in a Euclidean space $E^n,$ does there always exist a polynomial function $f_{A,B}:E^n\to\mathbb R$ that perfectly separates the collections?  That is, $f_{A,B}$ has positive values on all points of $A$ and negative values on all points of $B.$

The answer is yes, by construction.
Let $|\ |$ be the usual Euclidean distance. Its square is a quadratic polynomial.  Specifically, using any orthogonal coordinate system write $\mathbf{x}=(x_1,\ldots, x_n)$ and $\mathbf{y}=(y_1,\ldots, y_n).$  We have
$$|\mathbf{x}-\mathbf{y}|^2 = \sum_{i=1}^n (x_i-y_i)^2,$$
which explicitly is a quadratic polynomial function of the coordinates.
Define $$f_{A,B}(\mathbf x)=\left[\sum_{\mathbf y\in A}\frac{1}{|\mathbf x-\mathbf y|^2}-\sum_{\mathbf y\in B}\frac{1}{|\mathbf x-\mathbf y|^2}\right]\prod_{\mathbf y\in A\cup B}|\mathbf x-\mathbf y|^2.$$
Notice how $f_{A,B}$ is defined as a product.  The terms on the right hand side clear the denominators of the fractions on the left, showing that $f$ is actually defined everywhere on $E^n$ and is a polynomial function.
The function in the left term of the product has poles (explodes to $\pm \infty$) precisely at the data points $\mathbf x \in A\cup B.$  At the points of $A$ its values diverge to $+\infty$ and at the points of $B$ its values diverge to $-\infty.$  Because the product at the right is non-negative, we see that in a sufficiently small neighborhood of $A$ $f_{A,B}$ is always positive and in a sufficiently small neighborhood of $B$ $f_{A,B}$ is always negative.  Thus $f_{A,B}$ does its job of separating $A$ from $B,$ QED.
Here is an illustration showing the contour $f_{A,B}=0$ for $80$ randomly selected points in the plane $E^2.$  Of these, $43$ were randomly selected to form the subset $A$ (drawn as blue triangles) and others form the subset $B,$ drawn as red circles.  You can see this construction works because all blue triangles fall within the gray (positive) region where $f_{A,B}\gt 0$ and all the red circles fall within the interior of its complement where $f_{A,B}\lt 0.$

To see more examples, modify and run this R script that produced the figure.  Its function f, defined at the outset, implements the construction of $f_{A,B}.$
#
# The columns of `A` are all data points.  The values of `I` are +/-1, indicating
# the subset each column belongs to.
#
f <- function(x, A, I) {
  d2 <- colSums((A-x)^2)
  j <- d2 == 0           # At most one point, assuming all points in `A` are unique
  if (sum(j) > 0)        # Avoids division by zero
    return(prod(d2[!j]) * prod(I[j]))
  sum(I / d2) * prod(d2)
}
#
# Create random points and a random binary classification of them.
#
# set.seed(17)
d <- 2   # Dimensions
n <- 80  # total number of points
p <- 1/2 # Expected Fraction in `A`
A <- matrix(runif(d*n), d)
I <- sample(c(-1,1), ncol(A), replace=TRUE, prob=c(1-p, p))
#
# Check `f` by applying it to the data points and confirming it gives the
# correct signs.
#
I. <- sign(apply(A, 2, f, A=A, I=I))
if (!isTRUE(all.equal(I, I.))) stop("f does not work...")
#
# For plotting, compute values of `f` along a slice through the space.
#
slice <- rep(1/2, d-2) # Choose which slice to plot
X <- Y <- seq(-0.2, 1.2, length.out=201)
Z <- matrix(NA_real_, length(X), length(Y))
for (i in seq_along(X)) for (j in seq_along(Y))
    Z[i, j] <- f(c(X[i], Y[j], slice), A, I)
#
# Display a 2D plot.
#
image(X, Y, sign(Z), col=c("Gray", "White"), xaxt="n", yaxt="n", asp=1, bty="n",
      main="Polynomial separator of random points")
contour(X, Y, Z, levels=0, labels="", lwd=2, labcex=0.001, add=TRUE)
points(t(A), pch=ifelse(I==1, 19, 17), col=ifelse(I==1, "Red", "Blue"))

Comment: That is correct.  However, constructing such polynomials requires a $O(n^2)$ algorithm, whereas the method I have shown here is $O(n).$  That is one reason I chose it.
Comment: Thank you so much! That is just a perfect answer, though it takes some time to digest :)
Comment: Going through your answer again I came up with a question. Can I interpret it in the following way? Since for a data point $x$ to be in positive class just requires positive value of polynomial $P(x)$ in hypothesis $\frac{1}{1 + e^{-P(x)}}$, then according to the fact that a polynomial of high enough degree can approximate any continuous function, we can come up with a decision boundary of any form, because that polynomial $P(x)$ just needs to spit positive values for our positive class data points and negative values for our negative class data points...
Comment: ...Assuming there is no overlapping points from different classes, there is always a suitable function $f(x)$ that does its job spitting values of different sign for different classes (no matter what values, they just need to be of different signs). And for $n$ data points you need at most polynomial of degree $n$, since $n$-degree polynomial can always pass through $n$ non-overlapping points.
Comment: Thank you again! :)
Answer: There are a few problems with your first paragraph which may make your question difficult to answer.

We know that a polynomial can approximate any function.

Can it?  If you're referring to a Taylor polynomial, then the function must be smooth.  Not every function is a smooth function.

In binary logistic regression we're trying to fit a decision boundary to our data.

This isn't true.  Logistic regression seeks to estimate the coefficients for a model
$$ p(x) = \dfrac{1}{1 + \exp(-x^T\beta)} $$
There is no decision boundary here, and any cut off is imposed post facto.
Comment: Your first assertion (that polynomials can only approximate "smooth" functions) is incorrect.  (In mathematics, "smooth" always means having a sufficient number of derivatives--usually infinitely many.) The [Stone-Weierstrass theorem](https://en.wikipedia.org/wiki/Stone%E2%80%93Weierstrass_theorem) asserts that any *continuous* function on an interval can be approximated by polynomials.  Fourier analysis abounds with polynomial bases that can approximate merely piecewise continuous functions.
Comment: @mathgeek  The question is still not really a great one.  With finite data, we won't be able to learn the boundary exactly.  That being said, we might be able to do "good enough" for some sense of good enough.  Polynomials can can form a variety of decision boundaries, so the polynomial might be able to do good enough, but as I alluded to there are a bunch of functions which can not be expressed as a polynomial.
Comment: Thank you for your comment. I agree, it was my fault to poorly formulate the first paragraph, but what about my question? Can polynomial logistic regression learn any arbitrary decision boundary?


Subtract Everything After the last period

Question: Right now I am using this on my string substr($row->review[$i] , 0, 120) but I would like to take it a bit further and after I limit it find the last period and take out everything after. Any ideas?
Answer: $a = 'string you got with substr. iwehfiuhewiufh ewiufh . iuewfh iuewhf
     iewh fewhfiu h. iuwerfh iweh f.ei wufh ewifh iuhwef';

$p = strrpos($a, '.');
if ($p !== false) // Sanity check, maybe there isn't a period after all.
  $a = substr($a, 0, $p + 1 /* +1 to include the period itself */);
echo $a;

Comment: All in one line:  `if (($p = strrpos($a, '.')) !== false) $a = substr($a, 0, $p + 1);`
Comment: @Xeoncross Yes, I usually do that too, though it may be a little less readable for a beginner.
Answer: As Alex pointed out, strrpos() can find the location of the last occurrence of a sub-string:
$offset = strrpos($row->review[$i],'.');

Then you use this offset to slice off the last part of the main variable:
echo substr($row->review[$i],$offset);

Answer: See the documentation on strrpos().
Answer: This is a rather easy solution and will work no matter how long the extension or how many dots or other characters are in the string.
$filename = "abc.def.jpg";

$newFileName = substr($filename, 0 , (strrpos($filename, ".")));

//$newFileName will now be abc.def

Basically this just looks for the last occurrence of . and then uses substring to retrieve all the characters up to that point.
It's similar to one of your googled examples but simpler, faster and easier than regular expressions and the other examples. Well imo anyway. Hope it helps someone.


PowerShell search for multiple strings on one line

Question: Spent a few days going through a few dozen examples but, unfortunately, not found a solution yet. Hoping you guys can help.
I need to search a bunch of log files at once and on each line check today's date and for a specific string - and importantly, i need a count of the two combined occurrences.
I can do the individual search using Select-String. Even together. however, getting a count of it - while searching for both items on the same line has been the biggest hurdle.
Some of logs are renamed overnight and a suffix appended to them - this should explain the search criteria I've used.
This is the code example:
**$dateStr = Get-Date -Format "yyyy-mm-dd"
$searchStr = 'some.class.name'
(Get-ChildItem -Filter "*info*.log*" -Recurse | Select-String -pattern "$dateStr.$searchStr" -AllMatches).matches.count**

This version (i have many), is perhaps the simplest version and more instructive to what i am trying to achieve and for those who are willing to help.
Comment: Change `-pattern "$dateStr.$searchStr"` to `-pattern "$dateStr.+$([regex]::Escape($searchStr))"`
Answer: Assuming the date always precedes the part of the message you're searching for, use .* or .+ to describe whatever might be in between the two:
# Get the date string - no special metacharacters here, so safe to use as-is
$date = Get-Date -Format yyyy-mm-dd

# The keyword we're searching for might have metacharacters, like `.`, so remember to escape it
$word = [regex]::Escape('some.class.name')

# Now construct the pattern - use `.+` to describe "1 or more of any character" in between the date and the word we're searching for
$pattern = "${date}.+${word}"

# Pipe the results to Measure-Object, might speed up processing time
$count = (Get-ChildItem -Filter "*info*.log*" -Recurse | Select-String -Pattern $pattern -AllMatches |ForEach-Object Matches |Measure-Object).Count

Comment: That worked!! - thank you for your fully kitted out and descriptive response. I've learnt a bit more about Powershell from your answer.


Pritunl server running on Azure VM - VPN clients have no internet

Question: I have a Pritunl VPN Server running on an Azure VM (ubuntu).
For testing purposes, I used the default configuration which routes all traffic through the VPN tunnel. My clients (some desktop pc's and some VPN travel routers) all connect successfully, can talk to each other, and have internet access.
I now want to stop routing client internet traffic through the VPN, but continue to route local traffic. I removed the default "0.0.0.0/0" route per the documentation. My clients can still connect and talk to each other, but none of the clients/device can access the internet.
It seems that with this configuration, DNS is not getting resolved and I'm not sure if it's a Pritunl issue, a client issue or even an issue with my VM's network configuration.
This is all pretty new to me, I'm not even sure where to begin debugging this and hope someone can help.
Other findings:

Using the official Pritunl client for windows, I DO have internet access.
(OpenVPN Connect and other ovpn clients do not work though)
This same
setup works well with OpenVPN Cloud Server (Pritunl Server is part of
the spec though)
Ping result to google: "Ping request could not find host google.com"
Answer: I seem to have solved this, I'm not sure if it's the correct solution, but it does work...
According to the Pritunl Docs here: Internal DNS or VPC DNS Server
When connected to the VPN, DNS queries still go through the VPN tunnel and are denied when they come from other networks. To solve this, create a /32 route to the VPC's DNS server and specify this as the DNS server for VPN clients to use.
Instead, I created a /32 route to 22.214.171.124 and 22.214.171.124 and set these as my client dns servers.
All of my requirements are now met.
Answer: Simply remove the DNS Server value in pritunl would work too
Comment: This worked for me


Show that there exists $0 \lt \tau \lt 1$ such that for all $0 \lt t \lt \tau,$ $f\left (\gamma(t) \right ) \neq 0.$

Question:
Let $\gamma : [0,1] \longrightarrow \left \{z \in \Bbb C\ |\ \left \lvert z \right \rvert \leq 1 \right \}$ be a non-constant continuous mapping such that $\gamma (0) = 0.$ Let $f$ be an analytic function in the disk $\left \{z \in \Bbb C\ |\ \left \lvert z \right \rvert \lt 2 \right \},$ such that $f(0) = 0$ and $f(1) = 1.$ Then, there exists $\tau$ such that $0 \lt \tau \lt 1$ and such that for all $0 \lt t \lt \tau,$ we have that $f \left (\gamma (t) \right ) \neq 0.$

If the result is false then for each $0 \lt \tau \lt 1$ there exists $0 \lt t_{\tau} \lt 1$ such that $f \left (\gamma \left (t_{\tau} \right ) \right ) = 0.$ If we can somehow prove that the set $\left \{\gamma \left (t_{\tau} \right )\ |\ 0 \lt \tau \lt 1 \right \}$ is infinite then by Bolzano-Weierstrass theorem it has a limit point (since the set is bounded) and then by using identity theorem we have $f \equiv 0,$ a contradiction to the fact that $f(1) = 1.$ But how do I prove the infinitude of the set? Any help in this regard will be highly appreciated.
Thanks in advance.
Answer: You cannot prove that statement, since it is false. Suppose that$$\gamma(t)=\begin{cases}0&\text{ if }t<\frac12\\t-\frac12&\text{ otherwise.}\end{cases}$$Then $\gamma(0)=0$ and $\gamma$ is continuous and non-constant. Now, suppose that $f(z)=z$, in which case $f$ is analytic, $f(0)=0$, and $f(1)=1$. However, if $\tau=\frac12$, then $0<t<\tau\implies f\bigl(\gamma(t)\bigr)=0$.
Comment: But @José Carlos Santos this question appeared in NBHM PhD entrance test $2018$ in India.
Comment: Do you see something wrong in my answer?
Comment: It was given that $f(1) = 1.$ See the question carefully. So you cannot take $f \equiv 0.$
Comment: It was a typo. I meant $f(z)=z$. Again, do you see something wrong in my answer?


How do Ordered Target Statistics work for CatBoost?

Question: This question follows closely this paper .
I'm trying to fully understand how Ordered Target Statistics (TS) (for CatBoost) works. E.g. the CatBoost algorithm uses this method to group categorical features through estimatation of numerical values $\hat{x}_{k}^{i} \approx \mathbb{E}\left(y \mid x^{i}=x_{k}^{i}\right)$  instead of one-hot-encode them.
Since this estimate can be noisy for low-frequency categories, one can smooth it by some prior p so that :
$\hat{x}_{k}^{i}=\frac{\sum_{j=1}^{n} \mathbb{1}_{\left\{x_{j}^{i}=x_{k}^{i}\right\}} \cdot y_{j}+a p}{\sum_{j=1}^{n} \mathbb{1}_{\left\{x_{j}^{i}=x_{k}^{i}\right\}}+a}$ where $a>0$ is some parameter.
Now, one uses the ordering principle which translates to me to order the (whole) data set $\mathcal{D}$ or some subsets of the dataset $\mathcal{D}_k$ given some ordering function. I anticipate that the ordering function in the CatBoost algorithm is the artificial "time" which they define as a random permutation $\sigma$ of the training examples. Then, for each example they use all the available "history".
What is meant by "history" in this method?
My best guess would be the following. In each step a random permutation is applied to $\mathcal{D}$. Afterwards $\mathcal{D}$ is split into training and test examples. Then the test examples were expanded with all the training examples of the past steps.
Answer: Catboost in order to calculate the ordered target statistics defines various permutations of the training data. Now at each step of the gradient boosting it chooses one of the permutation at random in order to calculate ordered ts.
Now the history refers the sample that appears before. Now lets look at the random sample from permutation below:

for Row ID - 9 , history comprises of Row ID - 2 but not Row ID - 3 as in this permutation it occurs after Row ID - 9
Answer: "What is meant by "history" in this method?"
The history of a data point $i$ refers to all data points appearing before data point $i$ in a given permutation.
"Afterwards D is split into training and test examples. Then the test examples were expanded with all the training examples of the past steps."
The artificial time only applies to training dataset $\mathcal{D}$. In the testing phase, the whole training dataset $\mathcal{D}$ is used to do TS encoding.
To avoid target leakage, we can actually divide the training set $\mathcal{D}$ into $\mathcal{D}_1$ and $\mathcal{D}_2$, and then using $\mathcal{D}_1$ to do TS encoding and $\mathcal{D}_2$ for training. But this is a waste of your training data. They then figured out a way, i.e. ordered TS encoding, to avoid target leakage and at the same time utilize full training dataset $\mathcal{D}$. This idea is not only used to encode categorical features but also to build base learners in boosting. This target leakage in the boosting machine has been overlooked by people until catboost.
The ordered TS encoding is explained in other answer. It is worth noting that the encoding has large variance for data points with short history, and that is why they utilized many permutations (or artificial times) in different iterations of the boosting process. Notice that this does not mean that different artificial times are used to encode different categorical features. It is actually the same sampled artificial time used to do all ordered TS encoding for all categorical features and also for constructing the base learner.


how to pass Intent to new activity from firebase recyclerview

Question: I am new to android development using Firebase. I get stuck in passing intent to new activity. I want to pass url and url1 to new activity when I click a particular card in recycler view.
Here is my code
MainActivity
<code>    myRef = FirebaseDatabase.getInstance().getReference("project").child("electronics");
    recyclerView = (RecyclerView) findViewById(R.id.recycle);
    recyclerView.setHasFixedSize(true);
    recyclerView.setLayoutManager(new LinearLayoutManager(this));

    FirebaseRecyclerAdapter<Project,BlogViewHolder> adapter = new FirebaseRecyclerAdapter<Project, BlogViewHolder>(
            Project.class,
            R.layout.card,
            BlogViewHolder.class,
            myRef
    ) {
        @Override
        protected void populateViewHolder(BlogViewHolder viewHolder, Project model, int position) {

            viewHolder.setProjectName(model.getProjectName());
            viewHolder.setUrl1(model.getUrl1());

            progressDialog.hide();
        }

    };

    recyclerView.setAdapter(adapter);

}

public  static class BlogViewHolder extends RecyclerView.ViewHolder implements View.OnClickListener {

    TextView project1;
    ImageView imageview;

    public BlogViewHolder(View itemView) {
        super(itemView);
        itemView.setOnClickListener(this);
        project1 = itemView.findViewById(R.id.textView);
        imageview = itemView.findViewById(R.id.projectImage);

    }

    public void setProjectName(String projectName) {
        project1.setText(projectName);
    }

    public void setUrl1(String url1) {
        Picasso.with(itemView.getContext())
                .load(url1)
                .into(imageview);
    }
</code>
Project.java
<code>public class Project {
private  String projectName,url,url1;

public Project() {
}

public Project(String projectName, String url, String url1) {
    this.projectName = projectName;
    this.url = url;
    this.url1 = url1;
}

public String getProjectName() {
    return projectName;
}

public void setProjectName(String projectName) {
    this.projectName = projectName;
}

public String getUrl() {
    return url;
}

public void setUrl(String url) {
    this.url = url;
}

public String getUrl1() {
    return url1;
}

public void setUrl1(String url1) {
    this.url1 = url1;
}}
</code>
Here is my Firebase Database
Database
Comment: Possible duplicate of [Android: Using an intent to start any activity](https://stackoverflow.com/questions/30959496/android-using-an-intent-to-start-any-activity)
Answer: Bundle.
you get model.getUrl() in String and use bundle to pass what you want.
in your onClick method
<code>@Override
public void onClick(View v) {
    switch (v.getId()) {
        case xxxx:
            Intent intent = new Intent(mActivity, nextActivity.class);
            Bundle bundle = new Bundle();
            String value = model.getUrl();
            bundle.putString(key, value);
            intent.putExtras(bundle);
            startActivity(intent);
            break;
    }
}
</code>
and In your nextActivity, you need to catch your bundle .
<code> private void getIntentData() {
    Bundle bundle = getIntent().getExtras();
    if (bundle != null)
        Strin url = bundle.getString(key);
}
</code>
Comment: how to pass bundle in onClick
Comment: where is your onClick method?
Comment: itemView.setOnClickListener(new View.OnClickListener() {

                @Override
                public void onClick(View view) {

                    Intent intent = new Intent(view.getContext(), projectView.class);

                    view.getContext().startActivity(intent);
                }
            });
        }

in intent i want to pass intent.putExtra(PROJECT_URL, project.getUrl()); this


Old bundle not being deleted after update and refresh - (re)moved packages

Question: I have a bundle com.elsten.bliss.platform. Here are the wirings before update:
g! inspect capability osgi.wiring.package 59
com.elsten.bliss.platform [59] provides:
----------------------------------------
osgi.wiring.package; com.elsten.bliss.client.impl 1.1.0 required by:
   com.elsten.bliss.ui [33]
osgi.wiring.package; com.elsten.bliss.licence 1.0.1 required by:
   com.elsten.bliss.ui [33]
osgi.wiring.package; com.elsten.bliss.main 2.0.5 required by:
   com.elsten.bliss.ui.systemtray [23]
   com.elsten.bliss.api [40]
osgi.wiring.package; com.elsten.bliss.music.policy.config 1.0.0 required by:
   com.elsten.bliss.ui [33]
   com.elsten.bliss.configuration.file [72]
osgi.wiring.package; com.elsten.bliss.music.policy.coverartpolicy 1.1.0 required by:
   com.elsten.bliss.ui [33]
osgi.wiring.package; com.elsten.bliss.music.policy.coverartpolicy.assessment 1.0.0 required by:
   com.elsten.bliss.ui [33]
osgi.wiring.package; com.elsten.bliss.music.policy.coverartpolicy.response 1.0.0 [UNUSED]
osgi.wiring.package; com.elsten.bliss.music.policy.fileorg 1.1.0 required by:
   com.elsten.bliss.ui [33]
osgi.wiring.package; com.elsten.bliss.music.policy.fileorg.pattern 1.0.0 required by:
   com.elsten.bliss.ui [33]
osgi.wiring.package; com.elsten.bliss.music.policy.fileorg.pattern.token 1.0.0 [UNUSED]
osgi.wiring.package; com.elsten.bliss.music.policy.tag.auto 1.0.0 required by:
   com.elsten.bliss.untagged.acoustid [52]
osgi.wiring.package; com.elsten.bliss.music.policy.tagsync 1.0.0 required by:
   jdbm-trunk-patched [20]
   com.elsten.bliss.ui [33]
osgi.wiring.package; com.elsten.bliss.music.policy.tagsync.allowablegenres 1.0.0 required by:
   com.elsten.bliss.ui [33]
osgi.wiring.package; com.elsten.bliss.music.policy.tagsync.consolidateartist 1.0.1 [UNUSED]
osgi.wiring.package; com.elsten.bliss.music.policy.tagsync.response 1.0.0 [UNUSED]
osgi.wiring.package; com.elsten.bliss.music.policy.tagsync.trackartist 1.0.0 [UNUSED]
osgi.wiring.package; com.elsten.bliss.music.policy.tagsync.tracknumberformat 1.0.0 required by:
   jdbm-trunk-patched [20]
osgi.wiring.package; com.elsten.bliss.music.policy2 1.0.1 required by:
   com.elsten.bliss.ui [33]
   com.elsten.bliss.configuration.file [72]
osgi.wiring.package; com.elsten.bliss.platform.storage.bus 1.0.0 [UNUSED]
osgi.wiring.package; com.elsten.bliss.platform.storage.file.jaudiotagger 1.0.0 required by:
   jdbm-trunk-patched [20]
osgi.wiring.package; com.elsten.bliss.platform.tagindex 1.0.0 [UNUSED]
osgi.wiring.package; com.elsten.bliss.platform.util2 1.0.0 required by:
   com.elsten.bliss.web.debug [14]
osgi.wiring.package; com.elsten.bliss.untagged2 1.0.0 required by:
   com.elsten.bliss.untagged.acoustid [52]
   com.elsten.bliss.ui [33]
osgi.wiring.package; com.elsten.bliss.platform.activity 1.0.0 [UNUSED]
osgi.wiring.package; com.elsten.bliss.platform2 1.0.0 [UNUSED]
osgi.wiring.package; com.elsten.bliss.platform.storage.file 1.0.0 required by:
   com.elsten.bliss.configuration.file [72]
osgi.wiring.package; com.elsten.bliss.music.conceptual 1.0.0 [UNUSED]
osgi.wiring.package; com.elsten.bliss.music.tagged.mapper 1.0.0 [UNUSED]
osgi.wiring.package; com.elsten.bliss.platform.storage.file.jaudiotagger.tag 28.1.2 [UNUSED]
osgi.wiring.package; com.elsten.bliss.music.policy.tagsync.regex 28.1.2 [UNUSED]
osgi.wiring.package; com.elsten.bliss.client.platform 1.0.0 [UNUSED]

And services:
g! inspect capability service 59
com.elsten.bliss.platform [59] provides:
----------------------------------------
service; com.elsten.bliss.client.Client with properties:
   service.id = 31
   Used by:
      com.elsten.bliss.ui [33]
service; com.elsten.bliss.licence.PerFixLicenceStore with properties:
   service.id = 32
   Used by:
      com.elsten.bliss.ui [33]
service; com.elsten.bliss.music.policy2.PerFixLicensedPolicyCommandExecutor with properties:
   service.id = 33
service; com.elsten.bliss.main.Platform with properties:
   component.id = 5
   component.name = com.elsten.bliss.main.PlatformImpl
   coverArtLookupStrategy.target = (rootLookupStrategy=true)
   informationSource.target = (getTags=true)
   service.id = 34
   Used by:
      com.elsten.bliss.api [40]
      com.elsten.bliss.ui.systemtray [23]

Now I update, which updates the bundle and a number of bundles besides. I perform this with a management agent coded by myself which uses OBR to update the new bundle versions and then calls refresh.
After this occurs, I set a breakpoint in com.elsten.bliss.main.PlatformImpl so I can test the wirings again. I expect that the old com.elsten.bliss.main.Platform has been removed. However:
g! lb platform
START LEVEL 1
   ID|State      |Level|Name
   59|Active     |    1|com.elsten.bliss.platform (28.1.2)
   84|Resolved   |    1|com.elsten.bliss.platform (28.1.3)

Now there are two versions! So I print the wiring (at this stage the services are not wired so no point in including them):
g! inspect capability osgi.wiring.package 59
com.elsten.bliss.platform [59] provides:
----------------------------------------
osgi.wiring.package; com.elsten.bliss.client.impl 1.1.0 required by:
   com.elsten.bliss.ui [33]
osgi.wiring.package; com.elsten.bliss.licence 1.0.1 required by:
   com.elsten.bliss.ui [33]
   com.elsten.bliss.platform [84]
osgi.wiring.package; com.elsten.bliss.main 2.0.5 required by:
   com.elsten.bliss.ui.systemtray [23]
   com.elsten.bliss.api [40]
osgi.wiring.package; com.elsten.bliss.music.policy.config 1.0.0 required by:
   com.elsten.bliss.ui [33]
   com.elsten.bliss.configuration.file [72]
osgi.wiring.package; com.elsten.bliss.music.policy.coverartpolicy 1.1.0 required by:
   com.elsten.bliss.ui [33]
osgi.wiring.package; com.elsten.bliss.music.policy.coverartpolicy.assessment 1.0.0 required by:
   com.elsten.bliss.ui [33]
osgi.wiring.package; com.elsten.bliss.music.policy.coverartpolicy.response 1.0.0 [UNUSED]
osgi.wiring.package; com.elsten.bliss.music.policy.fileorg 1.1.0 required by:
   com.elsten.bliss.ui [33]
osgi.wiring.package; com.elsten.bliss.music.policy.fileorg.pattern 1.0.0 required by:
   com.elsten.bliss.ui [33]
osgi.wiring.package; com.elsten.bliss.music.policy.fileorg.pattern.token 1.0.0 [UNUSED]
osgi.wiring.package; com.elsten.bliss.music.policy.tag.auto 1.0.0 required by:
   com.elsten.bliss.untagged.acoustid [52]
osgi.wiring.package; com.elsten.bliss.music.policy.tagsync 1.0.0 required by:
   com.elsten.bliss.ui [33]
osgi.wiring.package; com.elsten.bliss.music.policy.tagsync.allowablegenres 1.0.0 required by:
   com.elsten.bliss.ui [33]
osgi.wiring.package; com.elsten.bliss.music.policy.tagsync.consolidateartist 1.0.1 [UNUSED]
osgi.wiring.package; com.elsten.bliss.music.policy.tagsync.response 1.0.0 [UNUSED]
osgi.wiring.package; com.elsten.bliss.music.policy.tagsync.trackartist 1.0.0 [UNUSED]
osgi.wiring.package; com.elsten.bliss.music.policy.tagsync.tracknumberformat 1.0.0 [UNUSED]
osgi.wiring.package; com.elsten.bliss.music.policy2 1.0.1 required by:
   com.elsten.bliss.ui [33]
   com.elsten.bliss.configuration.file [72]
osgi.wiring.package; com.elsten.bliss.platform.storage.bus 1.0.0 [UNUSED]
osgi.wiring.package; com.elsten.bliss.platform.storage.file.jaudiotagger 1.0.0 [UNUSED]
osgi.wiring.package; com.elsten.bliss.platform.tagindex 1.0.0 [UNUSED]
osgi.wiring.package; com.elsten.bliss.platform.util2 1.0.0 required by:
   com.elsten.bliss.web.debug [14]
osgi.wiring.package; com.elsten.bliss.untagged2 1.0.0 required by:
   com.elsten.bliss.untagged.acoustid [52]
   com.elsten.bliss.ui [33]
osgi.wiring.package; com.elsten.bliss.platform.activity 1.0.0 [UNUSED]
osgi.wiring.package; com.elsten.bliss.platform2 1.0.0 [UNUSED]
osgi.wiring.package; com.elsten.bliss.platform.storage.file 1.0.0 required by:
   com.elsten.bliss.configuration.file [72]
osgi.wiring.package; com.elsten.bliss.music.conceptual 1.0.0 [UNUSED]
osgi.wiring.package; com.elsten.bliss.music.tagged.mapper 1.0.0 [UNUSED]
osgi.wiring.package; com.elsten.bliss.platform.storage.file.jaudiotagger.tag 28.1.2 [UNUSED]
osgi.wiring.package; com.elsten.bliss.client.platform 1.0.0 [UNUSED]

And the new bundle:
g! inspect capability osgi.wiring.package 84
com.elsten.bliss.platform [84] provides:
----------------------------------------
osgi.wiring.package; com.elsten.bliss.client.impl 1.1.0 [UNUSED]
osgi.wiring.package; com.elsten.bliss.main 2.0.5 [UNUSED]
osgi.wiring.package; com.elsten.bliss.music.policy.config 1.0.0 [UNUSED]
osgi.wiring.package; com.elsten.bliss.music.policy.coverartpolicy 1.1.0 [UNUSED]
osgi.wiring.package; com.elsten.bliss.music.policy.coverartpolicy.assessment 1.0.0 [UNUSED]
osgi.wiring.package; com.elsten.bliss.music.policy.coverartpolicy.response 1.0.0 [UNUSED]
osgi.wiring.package; com.elsten.bliss.music.policy.fileorg 1.1.0 [UNUSED]
osgi.wiring.package; com.elsten.bliss.music.policy.fileorg.pattern 1.0.0 [UNUSED]
osgi.wiring.package; com.elsten.bliss.music.policy.fileorg.pattern.token 1.0.0 [UNUSED]
osgi.wiring.package; com.elsten.bliss.music.policy.tag.auto 1.0.0 [UNUSED]
osgi.wiring.package; com.elsten.bliss.music.policy.tagsync 1.0.0 [UNUSED]
osgi.wiring.package; com.elsten.bliss.music.policy.tagsync.allowablegenres 1.0.0 [UNUSED]
osgi.wiring.package; com.elsten.bliss.music.policy.tagsync.consolidateartist 1.0.1 [UNUSED]
osgi.wiring.package; com.elsten.bliss.music.policy.tagsync.response 1.0.0 [UNUSED]
osgi.wiring.package; com.elsten.bliss.music.policy.tagsync.trackartist 1.0.0 [UNUSED]
osgi.wiring.package; com.elsten.bliss.music.policy.tagsync.tracknumberformat 1.0.0 [UNUSED]
osgi.wiring.package; com.elsten.bliss.music.policy2 1.0.1 [UNUSED]
osgi.wiring.package; com.elsten.bliss.platform.storage.bus 1.0.0 [UNUSED]
osgi.wiring.package; com.elsten.bliss.platform.storage.file.jaudiotagger 1.0.0 [UNUSED]
osgi.wiring.package; com.elsten.bliss.platform.tagindex 1.0.0 [UNUSED]
osgi.wiring.package; com.elsten.bliss.platform.util2 1.0.0 [UNUSED]
osgi.wiring.package; com.elsten.bliss.untagged2 1.0.0 [UNUSED]
osgi.wiring.package; com.elsten.bliss.platform.activity 1.0.0 [UNUSED]
osgi.wiring.package; com.elsten.bliss.platform2 1.0.0 [UNUSED]
osgi.wiring.package; com.elsten.bliss.platform.storage.file 1.0.0 [UNUSED]
osgi.wiring.package; com.elsten.bliss.music.conceptual 1.0.0 [UNUSED]
osgi.wiring.package; com.elsten.bliss.music.tagged.mapper 1.0.0 [UNUSED]
osgi.wiring.package; com.elsten.bliss.platform.storage.file.jaudiotagger.tag 28.1.3 [UNUSED]
osgi.wiring.package; com.elsten.bliss.music.policy.tagsync.regex 28.1.3 required by:
   com.elsten.bliss.platform [59]
osgi.wiring.package; com.elsten.bliss.client.platform 1.0.0 [UNUSED]

So the new bundle is barely being used for anything.
My suspicion is that it's something to do with the withdrawal of the com.elsten.bliss.licence package. This was removed, but note that this always existed (before the update):
g! lb licence
START LEVEL 1
   ID|State      |Level|Name
   69|Active     |    1|com.elsten.bliss.licence (1.0.1)
g! inspect capability osgi.wiring.package 69
com.elsten.bliss.licence [69] provides:
---------------------------------------
osgi.wiring.package; com.elsten.bliss.licence 1.0.1 [UNUSED]

So this is an interesting case: I had a split package before update which I didn't know about. However, dependencies for that split package were wired to a bundle that got updated.  Subsequent to the bundle update, they are still wired to the old bundle. So does this stop those bundles being re-wired to the extant com.elsten.bliss.licence?
A new idea: before update, ensure that all bundles except for the bootstrap bundle are not started. Then, start Felix with just the bootstrap bundle, check the package wiring, then perform the update.
The results: another pointer to the split com.elsten.bliss.licence package being the problem. After the update, there are again two com.elsten.bliss.platform bundles. However, there is only one wiring on the old version:
osgi.wiring.package; com.elsten.bliss.licence 1.0.1 required by:
    com.elsten.bliss.platform [84]

The new version is now dependent on the old version because of the removed package!
Any advice (including don't have split packages you dimwit!) accepted ;)
Answer: Not sure I understand. You have the bundle installed twice (59 and 84). So you did not update 59 with a new jar. So it seems you did not do a bundle update on 59. You just installed the bundle again (84). So this would explain why 59 is still present and probably still in use after the refresh.
Comment: Then you need to check into the code which is doing the management. This is not an OSGi framework problem as far as I can see.
Comment: As BJ says, there are two instances of the same BSN: bundle IDs 59 and 84. This can **only** happen if the management layer does an install rather than an update. Whether that is your code or OBR, I don't know... but it's not the framework.
Comment: I think you forgot the "don't have split packages you dimwit! :-)" BJ! But yes, your management can never have done an update with this result or you got one hell of a strange framework.
Comment: Not quite... Originally there was just 59 (v28.1.2). Then I used OBR to deploy a new repository.xml containing v28.1.3 and some other bundles. AFAIK that calls `bundle.update()` under the covers. However, this got deployed as 84, leading to two installations, rather than replacing 28.1.2 as 59, as normally happens. I want to understand why that happened.
Comment: Sorry for being dumb, but do you mean my code or OBR? This code has been working fine for three years with updates every two weeks over that time. Clearly there's something wrong but I thought it must be a nuance of the wiring.
Comment: Clearly there's something wrong but I thought it must be a nuance of the wiring and the way bundle capabilities/requirements have changed between versions. I wondered whether the above (removing a package capability that other bundles depended on when another bundle also has that capability) was covered in the OSGi spec and what the behaviour should be.


How can access textfield ids with page id in JQM

Question: I have same id in two different pages in JQM.
Question:
How can I able to access these id with page ids
as we know that in JQM every page has its own id:
<code>$('#pageId #textfieldId').val();
</code>
Or some thing different?
Comment: This should work or `$.mobile.activePage.find('textarea').val();`
Comment: @Irfan Please stop trying to correct people's grammar in suggested edits. You keep replacing correct grammar with incorrect grammar. "How can I able to" and ["Can not able to"](http://stackoverflow.com/review/suggested-edits/4478116) aren't just a little off, they're ***glaringly*** incorrect English, and in both cases the grammar was correct before you changed it. It's not just these two instances, I've noticed you do this sort of thing in the past. Please leave grammar corrections to those who have a reliable sense of English grammar.
Answer: Instead of:
<code>$('#pageId #textfieldId').val();
</code>
Use:
<code>$('.pageId .textfieldId').val();
</code>
You can only trigger unique ID's
Comment: Then I think you need to go for Omar's comment.
Comment: if i have two pages with ids profile and tool and a text field in both pages with same id then how can i access these ids because if i directly then there will be possibility of misunderstanding due to cache technique in JQM
Answer: Use the below code to get value of a text area in the active page.
<code>$.mobile.activePage.find('textarea').val();
</code>
Answer: <code>$('#pageId').find('textfieldId').val();
</code>


Drupal 7.x & GoDaddy Cron Jobs

Question: Has anyone successfully gotten cron jobs to work with GoDaddy shared hosting and Drupal 7.x?
This sort of thing is EASY if you have access to use wget or cURL but GoDaddy for some reason blocks access to their own shared servers through tools as wget and cURL. Why I don't know.
We are stuck with having to use
/web/cgi-bin/php "$HOME/html/drupal/cron.php"

but as described here: http://drupal.org/node/251481
that is bad since Drupal doesn't go through its bootstrap process and certain vars are not initalized. I also get the classic:
Status: 404
Content-type: text/html
No input file specified.

when I use this method. There is also the fact that D7.x requires a cron_key parameter passed along _cron.php?cron_key=XXXXXXXXXXXXX
Anyone have a solution...besides get the hell off GoDaddy?
Answer: Yes, I crated a cron.sh script and uploaded it on my server with the following content:
#!/bin/bash
# run drupal cron
echo "Start"
START=$(date +%s)
echo "Running Drupal Cron"
wget -O - -q -t 1 "http://<your-domain>.com/cron.php?cron_key=<your-key>"
END=$(date +%s)
DIFF=$(( $END - $START ))
echo "Total Time: $DIFF seconds"
echo "End"

I went into the GoDaddy hosting account and entered the cron command:
bash /home/content/00/00000000/cron.sh

NOTE: You will need to know the path of the location where the script resides on the server.  If you are using ssh you can get the path by typing "pwd" in the ssh command line.
Comment: "You will need to know the path of the location where the script resides on the server": Please how is this relevant and how would I apply this? I have the same issue. Thanks.

Drupal 7.x & GoDaddy Cron Jobs


Why not make the starting pistol predictable in running competitions?

Question: While real starting pistols are no longer used in track and field events, the electronic pistols used now still have a certain degree of uncertainty as runners cannot be fully sure when it would actually fire. This leaves some things to chance as runners who successfully gamble on starting before hearing the sound get a small advantage initially.
So why not solve the issue completely by making the starting sound 100% predictable? Events could use a system similar to motor sports where a set of three lights in fixed intervals indicate when the race begins. This would make it possible for athletes to reliably predict when to push off and leave absolutely nothing to chance.
Comment: The entire point of going away from your proposed system was that **everybody** would be able to go early, by a small fraction, before the gun. Now there is no way to know - and anybody who starts within a small margin of the gun is deemed to have false started. It's highly unlikely a runner can consistently get an advantage from gambling - so only those who react instead of gambling can get anywhere important in the long-term.
Comment: @Nij has the answer: the human starter is *supposed* to be unpredictable, so the race actually starts when the gun sounds and not when the runners expect it to sound. (It's a subtle difference, but in races won by hundredths of seconds, it's important.)
Comment: @Nij allow everyone to go at the very same millisecond as the "gun" goes off. Problem solved.
Comment: But your solution doesn't do that: some will learn the timing and go perfectly, so they're not reacting to the gun, they're going when they want to go. You're talking about a time trial, not a race.
Answer: IAAF rule 162.2 ("The start") says:

All races shall normally be started by the report of the Starter's gun held upwards.

and 162.6 ("False start") specifies that:

An athlete, after assuming a full and final starting position, shall not commence his start until after receiving the report of the gun.

Your question, I think, proposes changing this rule, and you're looking for arguments against. The IAAF rules don't offer justifications, so it's difficult to argue from grounds more specific than "but that's the rules", but here are two reasons a mechanical system would not work:

Set: Races where athletes are likely to gain an advantage by anticipating the start are also in the races which include a "set" stage in the start sequence ("To your marks," "set", BANG). The rules provide for the starter verifying that all athletes are in the proper set position (also defined in the rules) before sounding the gun. They could do this before allowing a mechanical process to take over, but because the time between "set" and the start is the main unpredictable variable for starters, this probably wouldn't help much. In other words, to make the start truly predictable, we would need to remove the requirement that the starter verify all runners are in the "set" position before starting.
Jumping the gun: The idea that the start should be predictable changes the actual race being timed. As the rules currently stand, the race starts with the athlete hearing the starting sound and ends when their torso breaks the plane of the finish line. As such, the athlete's ability to react to the starting sound efficiently and effectively is part of the event as it stands. By making the start predictable, you change the beginning of the race to being from the starting signal, and you allow the athlete to anticipate the signal (as long as they don't actually move). (I hope I've explained that change clearly enough.) This changes the race significantly on paper even if it seems like a slight change in theory.
Comment: You can start the three lights/beeps after the set position has been verified. That's how it works in Motorsports.
Comment: You can put brakes on a car. Making a group of people hold a pose has its own problems; gamesmanship is more likely as well.


Dangers of closing file descriptors

Question: In the Stack Overflow question Check if a program exists from a bash script the accepted answer notes that closing stderr is dangerous:

(minor side-note: some will suggest 2>&- is the same 2>/dev/null but shorter - this is untrue. 2>&- closes FD 2 which causes an error in the program when it tries to write to stderr, which is very different from successfully writing to it and discarding the output (and dangerous!))

Aside from an error in the writing program, what other dangerous things could happen?
Can using 2>&- potentially break the writing program (i.e. halt its execution and not allow cleanup)?
Comment: Define "dangerous". Writing to a closed file descriptor normally results in a simple error code from `write()` call. Many programs won't even check this error code because if you fail to write to `stderr` there's nothing you can do about it. I don't see anything dangerous here.
Comment: @DmitryGrigoryev. Re defining "dangerous". I guess that's what I'm trying to figure out and answer the question "Will using 2>&- break stuff"
Answer: Yes, it will break stuff, in exciting and interesting ways.
The problem is that Unix-like systems typically allocate file descriptors sequentially.  When a program wants a new file descriptor (ie they call open(), socket(), and any other function that allocates an fd) the kernel will find the lowest-numbered "free" descriptor, and hand that out.
Imagine now, if you will, that you have closed fd 2 (stderr).  Something in the process then wants a file descriptor (the next open file).  The kernel goes looking for a free fd, sees that fd 2 is unused, and gives that back to the program.
Now, imagine something else in the program wants to write to stderr.  It blindly writes to fd 2, because that where stderr lives.  Except now it doesn't.  If you're lucky, fd 2 was opened read-only, and the write gets an error.  Everyone assumes that writes to stderr will always succeed, so that'll be fun.  At least as likely, though, is that the fd is read-write (five of the six fopen(2) modes are write-enabled -- r+, a, a+, w, or w+) and the message that was supposed to go to stderr has just ended up splattered into whoknowswhere.
Even more exciting, *file descriptors are inherited on fork().  That means that every child process will also have the ability to scribble somewhere unexpected.  Worse, even "safe" forking strategies, for example where all fds get closed before exec, typically don't touch fds 0, 1, or 2.  So your little breakage will almost certainly survive ordinary strategies meant to prevent disaster across process boundaries.
You may say, "well, I'll never use a library that writes to stderr, then, and I'll be careful never to write to stderr myself".  To that, I just have two things to say:

Future-you won't be that careful.  You'll forget that you closed stderr.
Everyone else who may ever have the misfortune to deal with your crazy code won't be that careful, either.

Friends don't let friends close stderr.  Womble out.  drops mic
Comment: Good point,s @kasperd.  Fixed.
Comment: Your last sentence gives the impression that it is acceptable to close stderr and then open a new descriptor to replace it. I am of a different opinion. You should not let any of file descriptors 0, 1, or 2 be closed - not even temporarily. If you need to replace them the `dup2` system call should be used.
Answer: It can be very-very bad and lead to undefined behaviour. Check my old question: MySQL replication shuts down after rotate of binlog.
We had closed fd 2 for mysql daemon and help message were written into binlog.info. This broke master-slave replication.
Comment: Good to see Oracle's showing their usual attention to quality... 8 months later and the bug's barely even been looked at.  Bet it was a fun bug to find.
Comment: Yep, i believe they won't fix it in a while. It was one outrageous bug. However yes, it was fun in the end.

Dangers of closing file descriptors


Bug/Issue tracker for Drupal 7?

Question: I would really like to port my website to Drupal 7, but my site requires an issue tracker. I tried the support module, but it seems heavily orientated towards support tickets (you must add clients, all users can't view eachothers tickets).
With the project issues module still working on complete Drupal 6 support, I really don't think I should be holding my breath.
What options are there, If I want a bug tracker on Drupal 7?
Answer: Solution 1: Do It Yourself
Add taxonomy terms

Status (Open, In Progress, Pending, Resolved, Closed) ,
Priority
(Low, Normal, High)

Create content type Issue,

add fields title, body, status, priority.

Set roles

Allow anonymous users to create content Issue
Allow administrators to edit and delete content Issue

Extras:
Use Views for issue reporting
Use Workbench for managing issues
Use Workflow for setting issue management workflow
Solution 2: Use an external issue management solution
Comparison of issue-tracking systems
I prefer an external solution because of its independency I can still handle issues even if my site is down.
Comment: Managed to get something going with your do it yourself solution. I prefer something integrated to drupal so I can have one unified look and feel to my site. Ty :)
Answer: Project for D7 is http://3281d.com/2011/10/26/report-from-project-7-sprint coming. It's going to be a while so holding your breath is not advised... but it's coming.

Bug/Issue tracker for Drupal 7?


How to test parent child relationship in react-testing-library?

Question: Lets say this is my HTML, created from using semantic-ui.
I select number 35 from my dropdown and the result becomes this:

  Comedy

Comedy

Ideally I want to test the parent items children like this:

parent: name="genre"
child: value="35", text = Comedy

This doesn't seem possible.
I can only test one selector level for example - by getByText('Comedy') which is too generic since there are other 'Comedy' elements on the same page.
So how to select something like this:
getByWhatever('Some parent').getChildByWhatever('Some child').exists()

Answer: You can use the within query to get elements within another specific element.
const combobox = screen.getByRole('combobox'); // Retrieve the parent
expect(combobox).toHaveAttribute('name', 'genre');
const link = within(combobox).getByRole('link', { name: 'Comedy' }); // Retrieve the link child from within the parent
expect(link).toHaveAttribute('value', '35');

Comment: Excellent. That works great. Though I'm curious why  screen.getByRole('combobox', {name: 'genre'}) is causing an error. This api says I can use it: https://testing-library.com/docs/queries/byrole/
Comment: When using `getByRole` query, the `name` refers to the element's accessible name, not the name property. That's why it fails in this case.
Comment: oh like aria-lable?
Comment: Yes, like having an aria-label on the element to provide an accessible name.


How to transfer data from model to view in codeigniter

Question: I'm building a basic todo app.
I created a new view called view_list which basically shows the list I press "show" in my lists archives.
I have this function in my model
public function get_list_details() {
    $sql = "SELECT * FROM lists";
    $query = $this->db->query($sql);
    return $query->row();
}

My controller is
public function show_list() {
    $this->load->model('model_lists');
    $data = $this->model_lists->get_list_details();
    $this->load->view('lists/view_list', $data);
}

How do I pass the id of the list I clicked on?
Currently the view list opens in tab using the list unique id
view_list?lid=e4zVyKBHXu
Comment: How did you go? I posted my answer for you.
Answer: You should try it like
public function show_list() {
    $this->load->model('model_lists');
    $model_data = $this->model_lists->get_list_details();
    $data['somename'] = $model_data->column_name;

    $this->load->view('lists/view_list', $data);
}

On view
<?php echo $somename;?>

Here are a good examples http://www.codeigniter.com/user_guide/database/results.html and http://www.codeigniter.com/user_guide/general/models.html#loading-a-model
Get all list
public function get_list_details() {
    $sql = "SELECT * FROM lists";
    $query = $this->db->query($sql);
    return $query->result();
}

Controller function
public function show_list() {
    $this->load->model('model_lists');
    $data['results'] = $this->model_lists->get_list_details();

    $this->load->view('lists/view_list', $data);
}

View
<?php foreach ($results as $result) {?>
  <?php echo $result->column_name;?>
<?php }?>


How to resolve below exception on tomcat

Question: I'm using "aws-java-sdk-1.11.427.jar" in my code and tomcat is refusing to start and shows below error:
But there is no compile time error..
java.util.concurrent.ExecutionException: org.apache.catalina.LifecycleException: Failed to start component [StandardEngine[Catalina].StandardHost[localhost].StandardContext[/api]]
    at java.util.concurrent.FutureTask.report(FutureTask.java:122)
    at java.util.concurrent.FutureTask.get(FutureTask.java:192)
    at org.apache.catalina.core.ContainerBase.startInternal(ContainerBase.java:939)
    at org.apache.catalina.core.StandardHost.startInternal(StandardHost.java:872)
    at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)
    at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1419)
    at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1409)
    at java.util.concurrent.FutureTask.run(FutureTask.java:266)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
    at java.lang.Thread.run(Thread.java:745)
Caused by: org.apache.catalina.LifecycleException: Failed to start component [StandardEngine[Catalina].StandardHost[localhost].StandardContext[/api]]
    at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:167)
    ... 6 more
Caused by: java.lang.NoClassDefFoundError: com/amazonaws/auth/AWSCredentials
    at java.lang.Class.getDeclaredFields0(Native Method)
    at java.lang.Class.privateGetDeclaredFields(Class.java:2583)
    at java.lang.Class.getDeclaredFields(Class.java:1916)
    at org.apache.catalina.util.Introspection.getDeclaredFields(Introspection.java:110)
    at org.apache.catalina.startup.WebAnnotationSet.loadFieldsAnnotation(WebAnnotationSet.java:262)
    at org.apache.catalina.startup.WebAnnotationSet.loadApplicationServletAnnotations(WebAnnotationSet.java:136)
    at org.apache.catalina.startup.WebAnnotationSet.loadApplicationAnnotations(WebAnnotationSet.java:66)
    at org.apache.catalina.startup.ContextConfig.applicationAnnotationsConfig(ContextConfig.java:328)
    at org.apache.catalina.startup.ContextConfig.configureStart(ContextConfig.java:778)
    at org.apache.catalina.startup.ContextConfig.lifecycleEvent(ContextConfig.java:299)
    at org.apache.catalina.util.LifecycleBase.fireLifecycleEvent(LifecycleBase.java:94)
    at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5105)
    at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)
    ... 6 more
Caused by: java.lang.ClassNotFoundException: com.amazonaws.auth.AWSCredentials
    at org.apache.catalina.loader.WebappClassLoaderBase.loadClass(WebappClassLoaderBase.java:1291)
    at org.apache.catalina.loader.WebappClassLoaderBase.loadClass(WebappClassLoaderBase.java:1119)
    ... 19 more

Comment: Try put `aws-java-sdk-1.11.427.jar` in tomcat lib folder.
Comment: @ErShakirAnsari if your question was answered please upvote and confirm the correct answer below for future reference
Comment: aws jar not packaged as part of your application
Comment: @KamilW. Thanks! it worked.
Comment: Glad to hear it, can you accept my answer as solution for your problem?
Comment: @ErShakirAnsari Upvote each answer which helped you understand your problem. Upvote and hit ✓ on answer which resolved your problem directly.
Answer: Just put aws-java-sdk-1.11.427.jar in tomcat lib folder


remover classe depois da 1 com Jquery

Question: tenho a seguinte situação onde quero adicionar um classe e remover o resto de pois da 1

esse e o html onde a div tem 3 classe ao executar a função quero remover todas as classes mais deixando a 1 e adicionando a classe star ficaria assim

$(".voted").removeClass().addClass('star');

Answer: Você estava quase conseguindo apenas faltou adicionar novamente a classe voted que havia removido:

$(function() {
  $('.voted').removeClass().addClass('voted star');
  console.log($('div').prop('class'));
})

teste

Comment: obrigado deu certo era tão facil .

remover classe depois da 1 com Jquery


freemarker, parse values from template

Question: Is it possible to make next using freemarker?
e.g. in template i specify some values (i hope my syntax isn't misleading):
${{}?{images are missing}}

Idea is that, if application can make value, then new value used in template, if can't - default value is used. Main point is that i need values ("1234:thumb") from template to create correct output.
Here application get "1234:thumb" and "3456:thumb" from template and create images based on these value. If imagecreation was successful (both images), path to images written back to output:

If either of images wasn't created, default value ("images are missing") written to output:
images are missing

So 2 questions:

is it possible to store that values in template and parse them?
what is correct way to output default value (if/else in template or in application)?
Comment: I would say that logic shouldn't be in the template.
Comment: @andy-pryor, yes, you are right, that it is wrong place for this logic. I done it in different way.
Answer: Lets say you have two variables for your two images: thumb1234 and thumb3456.
You can test whether these variables are set using the "??" operator.
<#if thumb1234?? && thumb3456??>

<#else>
    images are missing
</#if>

Comment: Thank you for answer, but it is not what i asked.

freemarker, parse values from template


Disk errors Event ID 51 on LSI MegaRAID 9240-8i in RAID 1

Question: I am working on a case of recurrent disk errors.
Server is running Windows Server 2012 R2 Standard.
There are two main disks on a mirrored RAID.
There is also an additional drive that is used for backup and normally left unmounted to Windows. I'm not sure which disk is generating the errors.
Initially the errors were happening every day, sometime during the backup.
I downloaded the LSI MegaRAID Storage Manager and ran a consistency check on the logical drive, the results were OK. The errors stopped during the week, but happened again Sunday and Monday.
I ran a defrag on the logical drive from Windows.
I ran a checkdisk on the unmounted backup drive, no issues detected.
The errors again stopped over the week, then returned on Sunday and Monday.
Error description:
disk 51
An error was detected on peripheral \Device\Harddisk2\DR12 during a paging operation.
Does anybody have a suggestion what to do to fix the issue for good?
What is the function of locating the physical drives? Could that fix my issue?
Thank you kindly.
Answer: Is the backup a USB disk? Sometime, I saw long-standing USB disks (eg: ones that are attached to a machine with long uptime and are not removed often) give all kind of errors, behaving erratically.
If it your case and the message refers to the USB disk, the message itself is effectively harmless. Here you can find some more information.
Comment: Thanks for answering! Yes the backup HDD is a USB. I haven't been able to confirm for sure if the disk errors are generated by the logical RAID or the backup disk.


Is is it possible to set an expiry time on the cached version of each node individually in a Drupal 6 website?

Question: Is is it possible to set an expiry time on the cached version of each node individually in a Drupal 6 website? The expiry time could be based on any factor.
Answer: Check out Scheduler.
From the project page:

This module allows nodes to be published and unpublished on specified dates.

What are some examples of factors for expiry date?
Comment: One factor could be the published date. Older nodes could be cached longer than newer nodes. The other could be the type of node. Page nodes could be cached longer than story nodes. I am looking forward to the first one thought. Thanks for the update.
Comment: By the way I just realized a big blunder. I meant to ask if  we could put an expiry time on the 'cached verion' of a node
Comment: It's not really clear what is your question - what do you want to achieve (paraphrase)? What modules are you using now?


The method for analyzing the repeated measures study when the data was non-normal distributions

Question: When we conduct the repeated measures data (a continuous dependent variable) by using the method of repeated measures ANOVA, GEE or Multilevel models, the data was need follow normally distributed (multivariate normal distribution in repeated measures ANOVA).
However, we always found the data not follow a normal distribution.
Sometimes, although we log transform this data or using the Box-Cox Transformation, it was non-normal distributions.
Thus, how to analysis the repeated measures study when the data was non-normal distributions? GLMM?
Thanks a lot!
Answer: Firstly, it's the residuals from the model that need to have a multivariate normal distribution, no the observed values. Additionally, small deviations that some statistical significance test picks up with largish sample sizes may be irrelevant (and conversely such tests may miss really severe deviations in case of small sample sizes). So, ignore formal tests and look at how bad the deviation really is. If you then still have a problem, read on.
Secondly, transformations as you mentioned may often help (e.g. cell counts in the blood, viral load and similar variables often need a log-transformation).
Thirdly, if there is some distribution that describes your data well (whether it's for categorical, ordinal, count, continuous or whatever data), then a model with that distribution and a multivariate random effect (the simplest version is where you assume all times to be equally correlated and have just a single random effect per person - that's what a GLMM typically does, which covers many standard distributions like normal, binary, binomial, Poisson etc.) would be a logical option. A typical version with full flexibility of that for multivariate normal data is the MMRM model (mixed effect model for repeated measures), which allows an unstructured covariance matrix between times. Getting that flexibility for more complex situations with more unusual distributions may be less well supported by modeling packages (but e.g. things like Stan as usable via rstan, brms and so on allow extremely flexible model specification, it just is more time consuming to code up so many details oneself).
Comment: Thank you very much for your help. As you mentioned, we think if the data not follow a normal distribution ( including transform the data ) and the residuals from the model not follow a multivariate normal distribution, the GLMM or MMRM model is the primary choice for the repeated measures  (a continuous dependent variable) . Am I understand right?


ubuntu mysql too many connections

Question: I am using django with mysql on ubuntu 12.04.
It's strange that when I tried to do very simple command in mysql, it will suggest error "ERROR 1040 (HY000): Too many connections"
All I want to do is create about 20 tables using a django mysql framework, south. I am the only user connecting mysql, how come there are too many connections?
I did not change the configuration file in mysql, so the max connections should be default 150, I believe.
Could anyone help me with that? Thanks a million
update 1:
After I restart mysql server and run show processlist, I found 26 connections even though I am not doing anything. Sometimes the number would drop to 10, and come up again at 25 or something. Is that normal?
update 2:
Okay, I found what's the problem. Thanks for your help.
Comment: what is the output for showprocess list in mysql? That would give a good insight about the connections.
Comment: Thanks for your comments, I have attached the result. Could you help me again, please? Thanks
Comment: What was the problem, can you please share it with us. I can't see any attached results. Thanks
Comment: Maybe the mysql library you are using isn't thread safe?
Answer: MySQL Connections are sometimes held in abeyance by the OS.
Many times a week, someone's application has lingering MySQL Connections that were supposedly closed by Apache or Python or PHP. Sure, it is closed in the eyes of the Application, but TIME_WAITs sometimes take precedence. There is a hack I recent discovered in ServerFault. I now this hack:
Here is a nice question about TIME_WAIT : How to forcibly close a socket in TIME_WAIT?. I use this answer: https://serverfault.com/a/329848/69271
In essence, I would run this on the Ubuntu machine:
SEC_TO_TIMEWAIT=1
echo ${SEC_TO_TIMEWAIT} > /proc/sys/net/ipv4/tcp_tw_recycle
echo ${SEC_TO_TIMEWAIT} > /proc/sys/net/ipv4/tcp_tw_reuse

Comment: Hi, I checked on my ubuntu machine, both the value of 'tcp_tw_recycle' and 'tcp_tw_reuse' are 0. And I don't know the way Django connects mysql is using socket or tcp.
Comment: Zero means infinite waiting. Setting those values to nonzero forces the timeout with a finite value.
Answer: Okay, let me answer my problem.
Later I found that I run another python script which I forgot to terminate. The script run every 1 second to query mysql database.
+-----+------+-----------------+----------+---------+------+-------+------------------+
| Id  | User | Host            | db       | Command | Time | State | Info             |
+-----+------+-----------------+----------+---------+------+-------+------------------+
| 384 | root | localhost       | EZ_Green | Sleep   | 2682 |       | NULL             |
| 407 | root | localhost       | EZ_Green | Sleep   | 2052 |       | NULL             |
| 411 | root | localhost:47347 | NULL     | Sleep   |    3 |       | NULL             |
| 412 | root | localhost:47350 | NULL     | Sleep   |    1 |       | NULL             |
| 445 | root | localhost       | EZ_Green | Sleep   |  972 |       | NULL             |
| 448 | root | localhost       | EZ_Green | Sleep   |  882 |       | NULL             |
| 451 | root | localhost       | EZ_Green | Sleep   |  792 |       | NULL             |
| 454 | root | localhost       | EZ_Green | Sleep   |  702 |       | NULL             |
| 457 | root | localhost       | EZ_Green | Sleep   |  612 |       | NULL             |
| 460 | root | localhost       | EZ_Green | Sleep   |  522 |       | NULL             |
| 463 | root | localhost       | EZ_Green | Sleep   |  432 |       | NULL             |
| 466 | root | localhost       | EZ_Green | Sleep   |  342 |       | NULL             |
| 469 | root | localhost       | EZ_Green | Sleep   |  252 |       | NULL             |
| 472 | root | localhost       | EZ_Green | Sleep   |  162 |       | NULL             |
| 475 | root | localhost       | EZ_Green | Sleep   |   72 |       | NULL             |
| 476 | root | localhost       | EZ_Green | Sleep   |   42 |       | NULL             |
| 478 | root | localhost       | EZ_Green | Sleep   |   12 |       | NULL             |
| 479 | root | localhost       | NULL     | Query   |    0 | NULL  | show processlist |
+-----+------+-----------------+----------+---------+------+-------+------------------+

But I still don't understand why it takes so many connections and they are all sleeping? I use python thread to execute another function that query database every 1 second.  There are 2 active python threads running constantly, and all the other threads are terminated when they finish. The script is here.
while True:
    now = time.time()
    if now < next:
        time.sleep(next - now)
        t = Thread(target=my_function,)
        t.start()# start a thread

    next += interval

Comment: I am not a python guy so cant tell with surety, it might be possible that the connection pool you are using is not closing connections properly. Its difficult to say anything without knowing what are you doing in my_function. For sqlalchemy connection objects are not thread safe (I am quoting the docs here), you might want to try and close the connections in the script itself and see if that helps.
Comment: Thanks. I guess it's the problem of django orm that I am using. Everytime a new thread is created, it will create a new database connection. And it seems the connection is not closed even after the thread is terminated.
Answer: I am not a python guy so cant tell with surety, it might be possible that the connection pool you are using is not closing connections properly. Its difficult to say anything without knowing what are you doing in my_function. For sqlalchemy connection objects are not thread safe (I am quoting the docs here), you might want to try and close the connections in the script itself and see if that helps.

ubuntu mysql too many connections


The menu (Navigation bar) becomes collapse unstylish for a few second. need Solution

Question: I am facing a problem after deactivating the pre-loader. When someone tries to open the website all the menu (Navigation bar) becomes collapse unstylish for a few seconds. After a while when the page has fully loaded the menu gets its style.
I think the CSS file is loading after the website is gets fully loaded, maybe this is the reason. How Can I solve this issue?
Comment: Please share debugging details. Where can we see the issue ?
Comment: show some screens or code to help us resolve this in some way
Comment: @HariomBalhara
https://gamanicoreafoundation.com/
please check this site. all the menu (Navigation bar) becomes collapse unstylish for a few seconds. After a while when the page has fully loaded the menu gets its style.
Comment: @Dev Please check the link
Comment: Welcome to StackOverflow! Please do not only link us to your webpage. You should also post a [minimal reproducible example](https://stackoverflow.com/help/minimal-reproducible-example) here in the question, because it will be hard for us dig through the website to find the problem. Goodluck :D
Answer: put the css inside head tag before any scripts etc,
add preload to your css and critical js files

Comment: https://gamanicoreafoundation.com/ please check this site. all the menu (Navigation bar) becomes collapse unstylish for a few seconds. After a while when the page has fully loaded the menu gets its style.
Comment: pls. try with below css
.header .navi-desktop-site ul li.menu-item-has-children > ul {display: none;}
Comment: @SunnyParsana, Superb job. my problem solving