a java.lang.NullPointerException when trying to read data from database with JPA

Question: i 'm student and i've a web application which have the jbpm 5 framework embeded on it(this question is not about any jbpm 5 related topic but about JPA and persistance of the jbpm classes on a MySql database).
This web app should run on tomcat 7 configured with the Bitronix transaction manager.
JPA is used to persist the jbpm related classes using 2 persistence-units , here is the persistance.xml :
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<persistence version="1.0" xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_1_0.xsd
http://java.sun.com/xml/ns/persistence/orm http://java.sun.com/xml/ns/persistence/orm_1_0.xsd" xmlns:orm="http://java.sun.com/xml/ns/persistence/orm" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/persistence">
     <persistence-unit name="org.jbpm.persistence.jpa" transaction-type="JTA">
        <provider>org.hibernate.ejb.HibernatePersistence</provider>
        <jta-data-source>java:comp/env/jdbc/testDS1</jta-data-source>
        <class>org.drools.persistence.info.SessionInfo</class>
        <class>org.jbpm.persistence.processinstance.ProcessInstanceInfo</class>
        <class>org.jbpm.persistence.processinstance.ProcessInstanceEventInfo</class>
        <class>org.drools.persistence.info.WorkItemInfo</class>
        <class>org.jbpm.process.audit.ProcessInstanceLog</class>
        <class>org.jbpm.process.audit.NodeInstanceLog</class>
        <class>org.jbpm.process.audit.VariableInstanceLog</class>

        <class>org.jbpm.task.Task</class>
        <class>org.jbpm.task.Comment</class>
        <class>org.jbpm.task.Attachment</class>
        <class>org.jbpm.task.I18NText</class>
        <class>org.jbpm.task.SubTasksStrategy</class>
        <class>org.jbpm.task.Deadline</class>
        <class>org.jbpm.task.Escalation</class>
        <class>org.jbpm.task.Reassignment</class>
        <class>org.jbpm.task.Notification</class>
        <class>org.jbpm.task.BooleanExpression</class>
        <class>org.jbpm.task.User</class>
        <class>org.jbpm.task.PeopleAssignments</class>

        <properties>

            <property name="hibernate.dialect" value="org.hibernate.dialect.MySQLDialect"/>

            <property name="hibernate.connection.autocommit" value="false"/>
            <property name="hibernate.max_fetch_depth" value="3"/>
            <property name="hibernate.hbm2ddl.auto" value="update" />
            <property name="hibernate.show_sql" value="false" />
            <property name="hibernate.transaction.manager_lookup_class" value="org.hibernate.transaction.BTMTransactionManagerLookup"/>
        </properties>

    </persistence-unit>
    <persistence-unit name="org.jbpm.task">
        <provider>org.hibernate.ejb.HibernatePersistence</provider>

        <class>org.jbpm.task.Attachment</class>
        <class>org.jbpm.task.Content</class>
        <class>org.jbpm.task.BooleanExpression</class>
        <class>org.jbpm.task.Comment</class>
        <class>org.jbpm.task.Deadline</class>
        <class>org.jbpm.task.Comment</class>
        <class>org.jbpm.task.Deadline</class>
        <class>org.jbpm.task.Delegation</class>
        <class>org.jbpm.task.Escalation</class>
        <class>org.jbpm.task.Group</class>
        <class>org.jbpm.task.I18NText</class>
        <class>org.jbpm.task.Notification</class>
        <class>org.jbpm.task.EmailNotification</class>
        <class>org.jbpm.task.EmailNotificationHeader</class>
        <class>org.jbpm.task.PeopleAssignments</class>
        <class>org.jbpm.task.Reassignment</class>
        <class>org.jbpm.task.Status</class>
        <class>org.jbpm.task.Task</class>
        <class>org.jbpm.task.TaskData</class>
        <class>org.jbpm.task.SubTasksStrategy</class>
        <class>org.jbpm.task.OnParentAbortAllSubTasksEndStrategy</class>
        <class>org.jbpm.task.OnAllSubTasksEndParentEndStrategy</class>

        <class>org.jbpm.task.User</class>

        <class>org.drools.persistence.info.SessionInfo</class>
        <class>org.jbpm.persistence.processinstance.ProcessInstanceInfo</class>
        <class>org.jbpm.persistence.processinstance.ProcessInstanceEventInfo</class>
        <class>org.drools.persistence.info.WorkItemInfo</class>

        <properties>

             <property name="hibernate.dialect" value="org.hibernate.dialect.MySQLDialect"/>
            <property name="hibernate.connection.driver_class" value="com.mysql.jdbc.Driver"/>
            <property name="hibernate.connection.url" value="jdbc:mysql://localhost:3306/jbpm5webexpl" />
            <property name="hibernate.connection.username" value="root"/>
            <property name="hibernate.connection.password" value="sdfsdf"/>

            <property name="hibernate.connection.autocommit" value="false" />
            <property name="hibernate.max_fetch_depth" value="3"/>
            <property name="hibernate.hbm2ddl.auto" value="create" />
            <property name="hibernate.show_sql" value="false" />
        </properties>
    </persistence-unit>
</persistence>

The persistance is working great and i got the database populated with data.So now i want to read from that data particularly from a table named "organizationalentity" which is generated by the persistance work on the database even if this table correspondant 's java class wasn't declared on the persistance.xml(it is weird for me but the table is created and contains data!! but i did it myself when i got the exception but it wasn't the solution). the java class of that table actually exists on a maven referenced jar and not on my packages that i've written myself (this was the reason for which i coudn't add some NamedQueries on it becose this class is a .class and not a .java..)
so i added on my classpath this new OrganizationalEntityDao.java class :
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;

import org.jbpm.task.OrganizationalEntity;

public class OrganizationalEntityDao {

    @PersistenceContext(unitName = "org.jbpm.task")
    static EntityManager em;

        public static OrganizationalEntity readById(int id) {
        return em.find(OrganizationalEntity.class,id);
    }
}

And when i run my application i got this error :
javax.el.ELException: /index.xhtml @142,119 listener="#{processBean.requestPage}": java.lang.NullPointerException
    at com.sun.faces.facelets.el.TagMethodExpression.invoke(TagMethodExpression.java:111)
    at com.sun.faces.facelets.tag.jsf.core.AjaxBehaviorListenerImpl.processAjaxBehavior(AjaxHandler.java:450)
    at javax.faces.event.AjaxBehaviorEvent.processListener(AjaxBehaviorEvent.java:113)
    at javax.faces.component.behavior.BehaviorBase.broadcast(BehaviorBase.java:106)
    at javax.faces.component.UIComponentBase.broadcast(UIComponentBase.java:760)
    at javax.faces.component.UICommand.broadcast(UICommand.java:300)
    at javax.faces.component.UIViewRoot.broadcastEvents(UIViewRoot.java:794)
    at javax.faces.component.UIViewRoot.processApplication(UIViewRoot.java:1259)
    at com.sun.faces.lifecycle.InvokeApplicationPhase.execute(InvokeApplicationPhase.java:81)
    at com.sun.faces.lifecycle.Phase.doPhase(Phase.java:101)
    at com.sun.faces.lifecycle.LifecycleImpl.execute(LifecycleImpl.java:118)
    at javax.faces.webapp.FacesServlet.service(FacesServlet.java:593)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:305)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
    at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:225)
    at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:123)
    at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:472)
    at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:168)
    at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:98)
    at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:927)
    at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:118)
    at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:407)
    at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1001)
    at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:585)
    at org.apache.tomcat.util.net.AprEndpoint$SocketProcessor.run(AprEndpoint.java:1770)
    at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(Unknown Source)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
    at java.lang.Thread.run(Unknown Source)
Caused by: java.lang.NullPointerException
    at entities.dao.OrganizationalEntityDao.readById(OrganizationalEntityDao.java:20)
    at entities.beans.ProcessBean.requestPage(ProcessBean.java:121)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
    at java.lang.reflect.Method.invoke(Unknown Source)
    at org.apache.el.parser.AstValue.invoke(AstValue.java:264)
    at org.apache.el.MethodExpressionImpl.invoke(MethodExpressionImpl.java:278)
    at com.sun.faces.facelets.el.TagMethodExpression.invoke(TagMethodExpression.java:105)
    ... 27 more

i should say that i was wondering the use of JPA for persisting entities (as the EJB work) on tomcat . i didn't use JDBC to do this work as JPA is alreay used.
well guys, any idea ? cheers.
Comment: You won't be able to load an entity if JPA doesn't know about this entity. It should be listed in your persistence.xml as all the other entities. And you rely on CDI dependency injection here, but it seems that you don't have any CDI container available. WHy don't you use the same way to load this entity as for all the other entities you use?
Comment: i ve added org.jbpm.task.OrganizationalEntity in the persistance.xml but it didn't resolve the problem alone and as i have understood from your comment is that the class containing the EntityManager must be managed by CDI or EJB , i thought that it can be done without that. i don't know if tomcat can have a CDI container or not.
Comment: i don't really use these entities myself , it is the jbpm framework who do it internally and i don't know how. thank you anyway.
Comment: You're not forced to use CDI. But the OrganizationalEntityDao code you posted relies on CDI (or another dependency injection framework) to work. Where did you get this DAO code from? Do you understand how it works, and what the annotation it contains does. Why don't you use the same kind of code that you're using everywhere else with success to load this OrganizationalEntity entity from the database?
Comment: Actually OrganizationalEntityDao is a JSF  Managed Bean. This won't do the CDI work of course..
Comment: i picked that code from an application using EJB and this is not possible in tomcat (unless i use the openEjb stuff)
Comment: well, u're right i don't really know that these annotations depend only on a EJB or CDI, i just tried it.
Answer:
Caused by: java.lang.NullPointerException
      at entities.dao.OrganizationalEntityDao.readById(OrganizationalEntityDao.java:20)
      at entities.beans.ProcessBean.requestPage(ProcessBean.java:121)

Your code is broken. What's on line 20 of OrganizationalEntityDao.java? I suspect you'll find a potential NPE -- the one you are encountering.


Subsetting multiple columns that meet a criteria

Question: I'm currently using a dataset with 2000 rows and several columns, a sample of my data looks like this:
mydata <- read.csv(file.choose(), header = T)

Northing Parasite

 63900     4080
 78300     3090
 90200       0
 211100      0
 230200    3990
 239000      0

How would I subset these two rows from the whole data set, and have them meet the criteria: Northing > 200000 ?
Thanks for your help, I'm still quite new to r.
Answer: With dplyr:
dplyr::filter(df, Northing > 200000)

  Northing Parasite
1   211100        0
2   230200     3990
3   239000        0

With base R:
df[df$Northing > 200000,]

  Northing Parasite
4   211100        0
5   230200     3990
6   239000        0

Another base R solution using subset:
subset(df, Northing > 200000)

  Northing Parasite
4   211100        0
5   230200     3990
6   239000        0


Trying to have an tkinter app save data into an SQLite3 database

Question: I am coding a small program to simply save text data and integer data
into an SQLite3 database.
I have created the db called test.db with the following code:
con = sqlite3.connect('test.db')
cur = con.cursor()
cur.execute('drop table if exists data')
cur.execute('create table data(t1 TEXT, i1 INT)')
con.commit()
print('DB created')

The problem is when I run it it tells
me that the cur.execute line requires strings as parameters, but I have already defined text1 as string with StringVar.
from tkinter import *
from tkinter import ttk
import sqlite3

def savedata(text1, int1):
    con = sqlite3.connect('test.db')
    cur = con.cursor()
    cur.execute(('INSERT INTO data (t1, i1) VALUES (?,?)', (text1, int1)))
    con.commit()
    print('record inserted in data')

root = Tk()
root.title("Little Program To Save Data")

mainframe = ttk.Frame(root, padding="3 3 12 12")
mainframe.grid(column = 0, row = 0, sticky = (N,W,E,S))
mainframe.columnconfigure(0, weight = 1)
mainframe.rowconfigure(0, weight = 1)

text1 = StringVar()
text_entry = ttk.Entry(mainframe, width = 20, textvariable=text1)
text_entry.grid(column = 2, row = 1, sticky = (N,W,E,S))

int1 = IntVar()
int_entry = ttk.Entry(mainframe, width = 20, textvariable=int1)
int_entry.grid(column = 2, row = 2, sticky = (N,W,E,S))

ttk.Button(mainframe, text = "Save!", command=savedata(text1, int1)).grid(column = 3, row = 3, sticky = (W, E))

for child in mainframe.winfo_children():
    child.grid_configure(padx = 5, pady = 5)

root.mainloop()

Answer: The code doesn't work because StringVar and IntVar are not the typical Python objects str and int, they actually represent Tcl variables which you might happen to set to contain values that can be classified either as string or integer.
The first thing you need to do is change savedata(text1, int1) to savedata(text1.get(), int1.get()) so you actually obtain the values stored in them. Secondly, the way you define the value for the command parameter in the Button widget is wrong because you are executing it instead of passing a function to be executed when you actually click the button. That is fixed by changing that part to command = lambda: savedata(...). Thirdly, you are calling
cur.execute(('INSERT INTO data (t1, i1) VALUES (?,?)', (text1, int1)))

but that will certainly fail, because you are passing a tuple to execute, what you actually want is:
cur.execute('INSERT INTO data (t1, i1) VALUES (?,?)', (text1, int1))

Now your code works, but there is no need to use Tcl variables here.
Comment: Thanks!! mmgp, well explained and demonstrated
Comment: Hi again mmgp, one more question.


Como fazer lembretes CSS ao passar o cursor do mouse?

Question: Como faço para exbir um tooltip ao passar o cursor do mouse sobre o ícone de interrogação ?
Veja o exemplo na figura abaixo :

Você também pode visualizar o exemplo clicando aqui.
Comment: Possível duplicata de [É possível fazer um tooltip com CSS puro?](http://pt.stackoverflow.com/q/101968/3635)
Comment: Depois da edição o sentido mudou totalmente, até então duplicata sim, não tem porque ser agressivo argumentando leia "entenda o texto". Recomendo que seja compreensivo e se discorda apenas comente **"não é isso o que preciso, o que preciso é isso ..."**. Ok? não tinha nada na pergunta original falando do posicionamento. Obrigado por compreender e recomendo que leia o link [seja respeitoso](http://pt.stackoverflow.com/help/be-nice) =)
Comment: @GuilhermeNascimento Olá, não há nada de duplicado, pois não estou perguntando como fazer um TOOLTIP. A indagação que faço é outra, leia e entenda o texto.
Comment: Reverti a pergunta, pois mudou completamente o sentido da original, e invalidou as respostas existentes. Se tem nova dúvida, faça em separado.
Answer: Para mostrar um elemento "flutuante" no mouseover:

.hm div {display:none;position:relative}
.hm:hover div {display:block;position:absolute;top:0;margin-left:40px}

/* daqui pra baixo é só estética para demonstração */
.hm {
  width:1.5em;height:1.5em;
  text-align:center;
  font:20px/1.5em "segoe ui",arial,helvetica,sans-serif;
  border:1px solid #999;
  border-radius:50%;
  color:#999;
}

.hm div {
  width:8em;
  color:#fff;
  background:#999;
  border-radius:5px;
  padding:5px;
}

?
Batatinha quando nasce esparrama pelo chão.

O importante está nas duas primeiras linhas do CSS.
Pra formatar o balão como no exemplo dado, aqui já tem a solução:

Botões pontudos e Balões de Texto

Só de curiosidade, eu escolhi a frase acima pq eu gosto dela exatamente como está. Mas se tiver algum erro especificamente de ortografia, me avisem.

esparramar
es.par.ra.mar
(es+parra+(ra)ma+ar2) vtd 1 Dispersar, espalhar, esparralhar. vint e vpr 2 Dispersar-se, espalhar-se
Answer:

.wrapper {
  text-transform: uppercase;
  background: #ececec;
  color: #555;
  cursor: help;
  font-family: "Gill Sans", Impact, sans-serif;
  font-size: 20px;
  margin: 100px 75px 10px 75px;
  padding: 15px 20px;
  position: relative;
  text-align: center;
  width: 200px;
  -webkit-transform: translateZ(0); /* webkit flicker fix */
  -webkit-font-smoothing: antialiased; /* webkit text rendering fix */
}

.wrapper .tooltip {
  background: #1496bb;
  bottom: 100%;
  color: #fff;
  display: block;
  left: -25px;
  margin-bottom: 15px;
  opacity: 0;
  padding: 20px;
  pointer-events: none;
  position: absolute;
  width: 100%;
  -webkit-transform: translateY(10px);
     -moz-transform: translateY(10px);
      -ms-transform: translateY(10px);
       -o-transform: translateY(10px);
          transform: translateY(10px);
  -webkit-transition: all .25s ease-out;
     -moz-transition: all .25s ease-out;
      -ms-transition: all .25s ease-out;
       -o-transition: all .25s ease-out;
          transition: all .25s ease-out;
  -webkit-box-shadow: 2px 2px 6px rgba(0, 0, 0, 0.28);
     -moz-box-shadow: 2px 2px 6px rgba(0, 0, 0, 0.28);
      -ms-box-shadow: 2px 2px 6px rgba(0, 0, 0, 0.28);
       -o-box-shadow: 2px 2px 6px rgba(0, 0, 0, 0.28);
          box-shadow: 2px 2px 6px rgba(0, 0, 0, 0.28);
}

/* This bridges the gap so you can mouse into the tooltip without it disappearing */
.wrapper .tooltip:before {
  bottom: -20px;
  content: " ";
  display: block;
  height: 20px;
  left: 0;
  position: absolute;
  width: 100%;
}

/* CSS Triangles - see Trevor's post */
.wrapper .tooltip:after {
  border-left: solid transparent 10px;
  border-right: solid transparent 10px;
  border-top: solid #1496bb 10px;
  bottom: -10px;
  content: " ";
  height: 0;
  left: 50%;
  margin-left: -13px;
  position: absolute;
  width: 0;
}

.wrapper:hover .tooltip {
  opacity: 1;
  pointer-events: auto;
  -webkit-transform: translateY(0px);
     -moz-transform: translateY(0px);
      -ms-transform: translateY(0px);
       -o-transform: translateY(0px);
          transform: translateY(0px);
}

/* IE can just show/hide with no transition */
.lte8 .wrapper .tooltip {
  display: none;
}

.lte8 .wrapper:hover .tooltip {
  display: block;
}

    I have a tooltip.

I am a tooltip!

Original: http://jsfiddle.net/raving/87865bq7/
Se quer algo minimalista:

/* Tooltip container */
.tooltip {
    position: relative;
    display: inline-block;
    border-bottom: 1px dotted black; /* If you want dots under the hoverable text */
}

/* Tooltip text */
.tooltip .tooltiptext {
    visibility: hidden;
    width: 120px;
    background-color: black;
    color: #fff;
    text-align: center;
    padding: 5px 0;
    border-radius: 6px;

    /* Position the tooltip text - see examples below! */
    position: absolute;
    z-index: 1;
}

/* Show the tooltip text when you mouse over the tooltip container */
.tooltip:hover .tooltiptext {
    visibility: visible;
}

Hover over me
  Tooltip text

Original: http://www.w3schools.com/css/css_tooltip.asp


bisection method on $f(x) = \sqrt{x} − 1.1$

Question: the question goes something like this :

Apply the bisection method using the code in slides to find the root of the function $f(x) = \sqrt{x} − 1.1$ starting from the interval $[0, 2]$ with a tolerance of $\epsilon = 1.e-8$

How many iterations are required ? Does the iteration count match the expectations, based on our convergence analysis ?
What is the resulting absolute error ? Could this absolute error be predicted by our convergence analysis ?

the first part of the question is pretty easy to code out and here is my code for the same :
<code>def func(x):
    return np.sqrt(x)-1.1

def bisection(a, b, tol):

    if (func(a) * func(b) >= 0):
        return

    c = a
    itercount=0
    while ((b-a) >= tol):

        c = (a+b)/2

        if (func(c) == 0.0):
            return c

        if (func(c)*func(a) < 0):
            b = c
        else:
            a = c
        itercount+=1
    return c, itercount
</code>
we get the theoretical number of iterations using the relation $n_{_{theoretical}} = \log_{_{2}} \left( \frac{b-a}{\epsilon}\right)$ which is very close to that counted by the programme ( $n_{_{calculated}} = 28$).
the absolute error = $8.94 \cdot 10^{-10}$ , but I have a problem understanding how this error could have been predicted by the convergence analysis, any hints or solutions are welcome.
Answer: Let $S_n$ be the $nth$ root approximation generated by the Bisection method, and $a_n,b_n$ denote the $nth$ $a,b$ for every iteration.
We also have the exact root $S$ between the interval  $(a,b)$ and $f(a)f(b)<0$ on the interval $[a,b] = [0, 2]$
For $n=1$, it is easy to see that $$b_1-a_1=b-a$$
For $n>1$, iterations of the Bisection method has been made so:
$$b_n-a_n=\frac{b-a}{2^{n-1}}$$
From the Biscetion method:
$$S_n=a_n+\frac{b_n-a_n}{2}$$
$$S_n-a_n=\frac{b_n-a_n}{2}$$
Obviously $S\in(a_n,b_n)$ so
$$|S_n-S|\leqslant \frac{b_n-a_n}{2}$$
$$|S_n-S|\leqslant\frac{b-a}{2^n}$$
Let $\epsilon = |S_n-S|$
$$\epsilon \leqslant\frac{b-a}{2^n}$$
$$n\leqslant \log_2(\frac{b-a}{\epsilon})$$
We now see that the $nth$ iteration corresponds to the distance between $S_n$ and $S$, which is bounded by $$\frac{b-a}{2^n}$$


httpd: Cannot make httpd to run under apache user

Question: I followed a few guides.

httpd is installed, running the service using sudo / so its as root, it works.

I have an apache user and group, and /etc/init.d/httpd is under apache:apache already.
But all I get is:
 Restarting httpd (via systemctl):  Failed to issue method call: Access denied
                                                           [FAILED]

This is my httpd folder ll -h
[alazarev@alazarev-asus etc]$ ll -h /etc/httpd/
total 8.0K
drwxrwxr-x. 2 apache apache 4.0K Jun  1 23:55 conf
drwxrwxr-x. 2 apache apache 4.0K Jun  1 23:55 conf.d
lrwxrwxrwx. 1 apache apache   19 Jun  1 23:55 logs -> ../../var/log/httpd
lrwxrwxrwx. 1 apache apache   27 Jun  1 23:55 modules -> ../../usr/lib/httpd/modules
lrwxrwxrwx. 1 apache apache   19 Jun  1 23:55 run -> ../../var/run/httpd
[alazarev@alazarev-asus etc]$

I am still not getting a clue where the problem is. By the way, my user has apache group appended:
[alazarev@alazarev-asus etc]$ id
uid=500(alazarev) gid=500(alazarev) groups=500(alazarev),10(wheel),48(apache) context=unconfined_u:unconfined_r:unconfined_t:s0-s0:c0.c1023
[alazarev@alazarev-asus etc]$

As you can see guys, I'm on: groups=500(alazarev),10(wheel),48(apache)
Answer: I'm not entirely sure if I'm reading your question correctly, but if Apache is binding to port 80/443, it has to be started as root--only root can bind to ports < 1024.  Once it's started, though, it'll become whatever user/group you have defined in your apache configuration.  ie:

User foo
Group bar


Computational complexity of solving linear diophantine equations?

Question: Is there any good complexity upper bound for checking satisfiability of a matrix system $Ax=b$ where $A\in \Bbb Z^{m\times n}$?
I found some estimate on computing the Smith Normal Form $N$ such that $SAT=N$ for invertible matrices $S$ and $T$, for example here: unfortunately, it is not very clear from the paper how the matrices $S$ and $T$ can be recovered, there is only one note at the end of Section 1 that they will do it "in the future".
I found a few other papers dealing with complexity of SNF, but either they only describe special cases (square, invertible..) or I couldn't see how to use them (without the unimodular matrices $S$ and $T^{-1}$).
I don't know whether I need to compute the Smith Normal Form at all.
The matrix I have in mind is a (co)boundary matrix between $k$- and $(k+1)$-simplices of a simplicial complex, if it helps.
Any help will be appreciated.
Comment: this looks good for a start: http://cs.nyu.edu/courses/spring13/CSCI-GA.3033-013/lectures/lecture-2.pdf
Comment: Thanks Will: but I don't see in this text anything about computational complexity, just an outline on how to compute the Hermite Normal Form (moreover, an algorithm about which authors say that it might not be even polynomial)...
Comment: this seems closer: http://cseweb.ucsd.edu/classes/wi10/cse206a/lec2.pdf
Comment: http://arxiv.org/pdf/1104.3720.pdf has actual references that appear worthwhile, refs pages 28-31 roughly
Comment: Just to be sure: by satisfiability you mean that $A$ and $b$ are given and you want to check whether there exists a vector $x$ solving the system (where $A$, $b$ and $x$ should all be integer-valued)?
Comment: Yes. I have already found one reference, but will be greateful for further comments.  Theorem 19 here http://e-collection.library.ethz.ch/eserv/eth:3348/eth-3348-01.pdf.
Answer: I would leave a comment but don't have the reputation: check out http://www.math.udel.edu/~lazebnik/papers/dioph2.pdf, which also looks to have several useful references (in particular http://www.math.tamu.edu/~rojas/kannanbachemhermitesmith79.pdf for algorithms to compute Smith normal form).
Comment: Thanks and welcome to MSE. The second paper shows polynomiality, but it is not easy to read of from the proofs a more exact order. But I will try :)


How to make an url dynamically in rails on form submit

Question: I have a form in rails :
<form class="clearfix" method="GET" action="<%= url_for hotels_path %>">
     <input type="text" name="country" />
     <input type="text" name="city" />
</form>

And i want on submit a redirect to the url :
/hotels/:country/:city

Where country and city are the values of my fields.
How can i manage this, whithout using javascript?
Thank you
Answer: You could do the redirect on server side e.g. like this (untested):
class HotelsController < ActionController::Base

    def index
       redirect_to hotels_path + "/#{params[:country]/#{params[:city]}"
    end

end

Answer: You cant manage this without using javascript because you set the action once while parsing your erb template and when you want to change it based on user action you must use javascript. Thats it!


Resolving samba server hostnames

Question: I have a samba server and I want to access it by name from my windows machine.
Currently if I can use the ip address e.g. \\192.168.0.104 (although it does not appear automatically in network) to access the machine from windows, but I would like to access it by name.  My understanding was that the simplest way to do this was using a hosts file.
I have tried adding
127.0.0.1 myservername

and
192.168.0.104 myservername

to the server, but this does not allow me to access by //myservername or ping myservername.  I understand I can edit the hosts file on my windows machine and give the ip a name,  but ideally I would like the name to be set by the server so I do not need to modify every other machine.  I think I have done this before using the hosts file but am no longer sure how it works exactly.
So how can I give my samba server a name accessible from windows?
Thanks
Comment: Samba server is running on which distro? Did your package manager also install `nmbd`?
Answer: You need to use a name service server like DNS, WINS or NetBIOS Name Service. Nowadays Windows is favoring DNS over WINS and NetBIOSNS is obsolete.
Add an A record for your samba server in the local DNS, make sure that all DNS clients are configured to use the same sub-domain. You can configure your DHCP server to send the proper DNS configuration to the clients.
To be able to see the server in My Network Places list, you might need to configure the same workgroup for all computers as it is on the samba server.
Comment: Add a DNS server on the same machine as the samba server?
Comment: You can but I would suggest adding it to your dhcp server instead.

Resolving samba server hostnames


What is [PSH, ACK] doing during my connection to a global catalog server?

Question: A linux server of mine is trying to establish a LDAPS connection to a global catalog server and the connection is getting dropped (presumably by the GC side).
For the purpose of discussion, let's say that 188.8.131.52 is the Linux server and 126.96.36.199 is the global catalog server.
If I try to use telnet from the Linux box, I see:
[root@foobox ~]# telnet gcfoo.exampleAD.local 3269
Trying 126.96.36.199...
Connected to gcfoo.examplead.local.
Escape character is '^]'.
Connection closed by foreign host.

There's no delay between the 4th and 5th lines.  It just immediately drops the connection.
I thought that telnet results might be a little misleading (since it's not actually appropriate for any type of secure communication) so I collected a packet capture of the actual connection attempt from the appliance (using the actual program requiring LDAPS).
Here's what I see (again, IPs and source ports have been renamed to protect the innocent):
No.     Time      Source     Destination      Protocol    Length    Info
1       0.000000  188.8.131.52    126.96.36.199          TCP         66        27246 > msft-gc-ssl [SYN] Seq=0 Win=5840 Len=0 MSS=1460 SAC_PERM=1 WS=128
2       0.000162  188.8.131.52    184.108.40.206          TCP         62        msft-gc-ssl > 27246 [SYN, ACK] Seq=0 Ack=1 Win=8192 Len=0 MSS=1460 SACK_PERM=1
3       0.000209  22.214.171.124    22.214.171.124          TCP         54        27246 > msft-gc-ssl [ACK] Seq=1 Ack=1 Win=5840 Len=0
4       0.003462  18.104.22.168    22.214.171.124          TCP         248       27246 > msft-gc-ssl [PSH, ACK] Seq=1 Ack=1 Win=5840 Len=194
5       0.007264  188.8.131.52    22.214.171.124          TCP         60        msft-gc-ssl > 27246 [RST] Seq=1 Win=64046 Len=0

I'm a bit rusty with TCP/IP so please forgive my ignorance...  I see the three-way handshake taking place in packets 1-3.  That makes sense.  What's going on in packet #4 though?  What does [PSH, ACK] mean? This seems like a redundant acknowledgement that's unnecessary. Is actual data being sent in this 4th packet? Or is this some weird continuation of the handshake?
Answer: PSH is a Push flag: http://ask.wireshark.org/questions/20423/pshack-wireshark-capture
The Push flag tells the receiver's network stack to "push" the data straight to the receiving socket, and not to wait for any more packets before doing so.
The Push flag usually means that data has been sent whilst overriding an in-built TCP efficiency delay, such as Nagle's Algorithm or Delayed Acknowledgements.
These delays make TCP networking more efficient at the cost of some latency (usually around a few tens of milliseconds). A latency-sensitive application does not want to wait around for TCP's efficiency delays so the application will usually disable them, causing data to be sent as quick as possible with a Push flag set.
On Linux, this is done with the setsockopt() flags TCP_QUICKACK and TCP_NODELAY. See man 7 socket for more information.
Answer: @DarkMoon explained what the PSH flag signifies. In regards to your data, the connection establishment completes (3-way handshake), then, yes, the client sent 194 bytes of data to the server (Len=194). The server did not like the data and closed the connection. Potentially the client isn't configured properly to communicate with the server or vice versa e.g. a SSL/TLS mismatch.
If you have access, I'd suggest examining the logs on the server to see if it logged what it didn't like about the client's data.


Como apresentar dados no ArrayList em java

Question: Como eu listo as informações armazenadas em um ArrayList no java?
Segue o código para análise.
public class Main {
    public static void main(String[] args) {
        Aluno aluno = new Aluno();
        ArrayList<Aluno> array_aluno = new ArrayList<Aluno>();
        for (int cont = 1; cont <= 3; cont++){
            aluno.setNome(JOptionPane.showInputDialog("Insira o nome do aluno: ") );
            aluno.setTelefone(JOptionPane.showInputDialog("Insira o telefone do aluno: ") );
            array_aluno.add(aluno);
        }

        for (int cont = 0; cont <= array_aluno.size() ; cont++){
            System.out.println(array_aluno.get(cont) );
        }
    }
}

Comment: Está correto, qual a dúvida?
Comment: Olá Giuliana! O programa executa, porém os três resultados impressos são apenas o último informado. Ex: Dados do Aluno Nome = SILVA Telefone = (55)9999-9999 (imprime três vezes na tela esse mesmo resultado, ignora os anteriores)
Comment: O problema no teu código é que você criou o objeto aluno fora do primeiro for, e por isso ele sempre está sendo sobrescrito. Você precisa criá-lo dentro do for, assim serão criados 3 objetos diferentes e não apenas 1.
Comment: Era isso mesmo Giuliana, coloquei o objeto aluno para ser criado dentro do for e deu certo.
Obrigado pela ajuda!
Answer: Na classe Aluno você pode sobrescrever o toString():
@Override
 public String toString() {
      return ("Nome:"+this.getNome() + " Telefone: "+ this.getTelefone());
 }

E usar esta estrutura no main:
public class Main {
    public static void main(String[] args) {
        ArrayList<Aluno> array_aluno = new ArrayList<Aluno>();
        for (int cont = 1; cont <= 3; cont++){
            Aluno aluno = new Aluno();
            aluno.setNome(JOptionPane.showInputDialog("Insira o nome do aluno: ") );
            aluno.setTelefone(JOptionPane.showInputDialog("Insira o telefone do aluno: ") );
            array_aluno.add(aluno);
        }

        System.out.println(array_aluno);
    }
}

Após comentário de Articundo, movi a criação do Aluno para dentro do for (o objeto estava sempre sendo sobrescrito).
Comment: Era isso mesmo, coloquei o objeto aluno para ser criado dentro do for e deu certo.
Obrigado pela ajuda!
Comment: Olá rLinhares! O programa executou, porém os três resultados impressos foram apenas o último informado. Ex:
Dados do Aluno
Nome = SILVA
Telefone = (55)9999-9999

Dados do Aluno
Nome = SILVA
Telefone = (55)9999-9999

Dados do Aluno
Nome = SILVA
Telefone = (55)9999-9999
Comment: Pelo que vi você não precisa do `for`. Vou removê-lo da resposta e você diz se resolveu.
Comment: O problema desse codigo é que ele nao vai gravar 3 alunos, e sim, sobrescrever o unico objeto aluno que está sendo criado.
Comment: @Articuno, tens razão, não tinha atentado.


AUC variance for estimators with randomness (e.g. Random Forest)

Question: I know that we can calculate the standard error for the AUC for all estimators, assuming that the conditional density is fixed. What I'd like to do, however, is additionally account for the randomness in certain estimators such as random Forest. I know that we can do a nonparametric bootstrap, where we resample and refit the estimator each time. However, I'm looking for a less computationally expensive approach.
Thanks!
Answer: I would just model the fact that each tree in a binary random forest votes for class 0 or class 1. This means that for $T$ trees, you have $T$ Bernoulli trials for each sample, and each sample $i$ has a different probability $p_i$ of being classified as 1 by a tree. These Bernoulli trials are IID because trees in a random forest are IID. A tree votes for class 1 some number of times $0\le k_i \le T$.
Adopting a Bayesian framework, we can leverage the beta-binomial model. The posterior distribution over $p_i$ for each sample is
$$
p_i \sim \text{Beta}(\alpha+k_i, \beta + T-k_i)
$$
where $(\alpha,\beta)$ is a prior belief about $p_i$. I wouldn't worry over choosing $(\alpha,\beta)$ too much; a uniform prior of $\alpha=\beta=1$ implies two "psuedo-RF-trees" voted for class 0 and class 1 once for each sample.
The rest is just monte carlo: for each $i$, sample from the posterior distribution and compute the ROC curve. Repeat this $M$ times, and you have a distribution of $M$ ROC curves drawn from this model.


oracle sql to find the rows with one or more duplicate results in a same table

Question: I have the below sample data set and I'm trying to come up with a query to find one or more duplicate rows from the same table
TABLE A:  with 2 columns as below
CODE_NAME, RESULT
ABC        1
BBC        1
ZZZ        5
ZZZ        6
ZZZ        7
KBC        2
ZBC        2
CCC        2
XYZ        3
MNC        4

And my output should give all the unique rows with duplicate values in the result column such as below
CODE_NAME, RESULT
    ABC        1
    BBC        1
    KBC        2
    ZBC        2
    CCC        2

i tried below but its not giving me correct result
select A t1, A t2
where A.result = b.result
and a.code_name <> b.code_name
Appreciate other suggestions.
Answer: You can use exists:
select t.*
from t
where exists (select 1
              from t t2
              where t2.result = t.result and t2.code_name <> t.code_name
             );

For performance on a large dataset, you want an index on (result, code_name).
You might find it more convenient to have one row per duplicated result:
select result,
       listagg(code_name, ',') within group (order by code_name)
from t
group by result
having count(*) > 1;

Comment: Thank you for the quick response for the data set I have... exists is taking a while to run whereas the listagg is much faster. thanks for that suggestion.


Maximize inner product with constraint

Question: I would like to solve the following maximization problem:
$$
max_x (x+y)^TM(x+y)  \\ s.t. \hspace{.25cm} x^Tx \leq 1
$$
Where M is symmetric and negative definite.
I can construct the lagrangian :
$$
max_x (x+y)^TM(x+y) + \lambda[r^Tr -1]
$$
I am able to derive the F.O.C.:
$$
M(x+y) = -2\lambda x
$$
When the constraint is not binding clearly x = - y, with unique max = 0. But I have no idea how to solve for the binding case.
If I assume invertibility of $[M + 2\lambda I]$ (which im not sure if I can do) I can arrive at:
$$
x = -[M+2\lambda I]^{-1}My
$$
Invoking the constraint (and symmetry):
$$
1 = y^T M [M+2\lambda I]^{-1}M^2[M+2\lambda I]^{-1}M y
$$
Which is 1 equation in 1 unknown and should have a unique solution for $\lambda$ which would solve the problem, but I see no way to do so.
Thank You for your help.
Comment: I don't think (could easily be wrong) that there is no closed form solution in general.
Comment: Might be easier to assume $M$ is diagonal with negative elements on the diahgonal.
Comment: Split into two cases. (1) $\|y\| \le 1$ and (2) otherwise.
Comment: @copper.hat Thanks, but I dont think I can do that. I am comfortable with symmetry and ND because in my application M is the hessian of a function evaluated at its global max, not sure if there's anything related to that that is helpful. As for the two cases, x = y in (1),  (2) seems to be the tricky one!
Comment: You can't do what?
Comment: assume M diagonal
Comment: If $M$ is symmetric then there is an orthonormal $U$ such that $U^TMU$ is diagonal.
Comment: Is this from a trust region method?
Comment: @copper.hat It is not from a trust region method, though it seems to be a similar problem. Thank you so much for noticing this!
Comment: I worked on various versions of TRMs a few decades ago. Mostly in the context of $\max$ functions.
Comment: As cooper.hat is saying, this is essentially the TRP, and the solution does not get much better than what you have. A numerical search along $\lambda$ is required.
Answer: $
\def\a{\alpha}\def\b{\beta}
\def\l{\lambda}\def\s{\sigma}
\def\o{{\tt1}}\def\p{\partial}
\def\LR#1{\left(#1\right)}
\def\trace#1{\operatorname{Tr}\LR{#1}}
\def\qiq{\quad\implies\quad}
\def\grad#1#2{\frac{\p #1}{\p #2}}
\def\c#1{\color{red}{#1}}
\def\CLR#1{\c{\LR{#1}}}
\def\fracLR#1#2{\LR{\frac{#1}{#2}}}
$In the binding case the problem becomes
$$\eqalign{
&\max_x\;&(x+y)^TM(x+y) \\
&{\rm s.t.}&x^Tx = \o \\
}$$
which can be solved by constructing the constrained variable $x$ from
an unconstrained variable $u$
$$\eqalign{
x &= \frac{u}{\|u\|} \qiq \grad xu
 = \fracLR{\|u\|^2I-uu^T}{\|u\|^3}
 = \fracLR{I-xx^T}{\|u\|}
\\
}$$
For typing convenience, introduce the vector
$$\eqalign{
z &= x+y \qiq dz = dx \\
}$$
Write the objective function and calculate its unconstrained gradient
$$\eqalign{
\phi &= z^TMz \\
d\phi &= 2Mz:dz = 2Mz:dx = 2\fracLR{I-xx^T}{\|u\|}Mz:du \\
\grad{\phi}{u} &= \fracLR{2}{\|u\|}\LR{I-xx^T}Mz \\
}$$
Setting the gradient to zero yields the eigenvalue equation of a rank-one matrix $\LR{xx^T}$
$$\eqalign{
\LR{xx^T}(Mz) &= (Mz) \\
\LR{xx^T}v &= \l v \\
}$$
whose only non-zero eigenpair is $(\l,v)=(\o,x).\;$
This leads to a soluble linear equation for the optimal $x$ vector
in the binding case
$$\eqalign{
&x = Mz = M(x+y) \\
&\LR{I-M}x = My \\
&x = \LR{I-M}^{-1}My \\
}$$

Maximize inner product with constraint


How to enable Submit Button after filling out the required fields?

Question: I have created custom Content Type and I would like to disable the submit button, till the user has filled out all the required fields.
I should enable the submit button, once the user fills out the required fields, how do i achieve this?
Comment: In which ever way you do, enable the submit button by default and disable it using Jquery on page load. At least it'll work without Jquery or javascript.
Answer: check out #states visible #states invisible in drupal.
http://api.drupal.org/api/examples/form_example!form_example_states.inc/function/form_example_states_form/7
http://api.drupal.org/api/drupal/includes!common.inc/function/drupal_process_states/7
Answer: This sounds like a job for javascript.
This thread should get you started:
http://www.webdeveloper.com/forum/showthread.php?147187-how-to-Disable-enable-submit-button-using-javascript.
I'd create a set of javascript validation functions that once they all returned true for the fields you need it would reenable the submit button.
Here is a link to another, simple, example that may be just what you are looking for:
http://www.webmasterworld.com/javascript/4083623.htm


Substituting two points in linear algebra

Question: One of the exercises in my eBook substitutes q - p and s - r.
My question is this; why did the book substitute in that order? Why not p - q and r - s?
Here's an image of the exercise in my book
Answer: In this case the order doesn't matter. If a vector $\vec v$ is a scalar multiple of $\vec u$, then clearly so is $-\vec v$.
Comment: So the two lines end up being parallel regardless of the order.
Comment: @LawrenceLelo That's right. You can think of the order as fixing a direction in which you trace the lines. Their being parallel or not is independent of this.
Answer: That was not neccessarily substition. What did happen was that the difference between the points determining the line was translated to the origin, which means that whereas q and p were "floating" in the plane before, the vector connecting the two is now emanating from the origin. The same was done for s-r - this makes it easier to compare the lines, as they coincide with these vectors.
Comment: Oh okay, I think I understand now. So q and p are just points floating at the given coordinates, and we found the difference between the two so we can work with the original line.
Comment: @LawrenceLelo Yes, in this case we are treating the vectors **p** and **q** as points in the plane. As these define the line $l_{1}$, they both lie on $l_{1}$. It follows from this that the vector connecting **p** and **q**, **q-p**, does too. Note that **q-p** is not the original line as **q-p** has a clear starting and ending point (it starts at the origin and ends at (-3, -2, 1)). It is simply a representative of the line. Try to make a drawing!


How to import Nodes and Node Location data using Feeds module?

Question: I would like to use Feeds to import Node Location data together with Nodes themselves.
Each node of a selected content type is or is not assigned to a location.
How to do this ?
Comment: Consider refining your question and don't ask yes/no questions. There is always a way (write a lot of code), so a simple and correct answer would be: "Yes".
Comment: I did something similar.  Here's my answer to this where I used SQL and feeds: [Drupal 7 content import](http://drupal.stackexchange.com/a/16131/2531)
Answer: Yes, definitely go with feeds except I would go with location module instead of geofield personally as it has direct support from the location_feeds module for mapping in all the relevant details. Its possible that you may need to do two seperate feeds (one for importing the node information and one for the location information) but you can make sure they "come together" by using the same GUID field from your feed on each one. The easiest way is to try :) Set up a dummy file first with only 10 imports.
Comment: I would like to import with two separate feeds as you mentioned above. Can you please explain in more detail "make sure they "come together" by using the same GUID field from your feed on each one". I tried to run two separate feeds and they create separate nodes although I use matching GUID field values in both.
Comment: I think I may have pulled that bit from memory with using Drupal 6 as it appears that http://drupal.org/project/feeds_node_multisource never made it to Drupal 7 (although Im sure I have done it through GUID in d7, I will see if I can dig up where). Do you have to do it with 2 seperate feeds? The location_feeds mapper should work anyway.
Comment: Thank you, I managed to use one source file for this data load.
Answer: Take a look at the Geofield module for mapping of location data when pulling in your feed. There's a page on the Drupal community documentation about mapping using Open Layers and Feeds that may help you.


Assumptions and terminology for dynamic regression with endogenous offset ($y_t=y_{t-1}+\beta X_{t-1}+\epsilon_t$)

Question: I'm dealing with a fairly simple time series regression model with the following basic form:
$y_t=y_{t-1}+\beta X_{t-1}+\epsilon_t$
I'm assuming that observations of $y$ are known without error. $X$ contains exogenous predictor variables, and $\beta$ contains the corresponding parameters to be estimated. $\epsilon$ are the errors.
I'm asking 1) if my terminology for this type of model is correct; 2) what assumptions and consequences apply/ are violated with I fit this model using OLS; 3) same as 2, but fit using MLE.
I expand on these slightly below.
1) Is the model a dynamical linear model, a transfer function, or something else? How do I state that it contains only process errors, not observation error on $y$? Because it only contains process error, it's not a "state space" representation, correct? Related to 2 & 3, I'm wondering if the changes I make when fitting this model with OLS vs. MLE should change how I refer to the model.
2) When fitting using OLS, I take the first difference of the dependent variables in R (i.e., delta.y <- diff(y)) so that the response in my regression basically becomes $\Delta y_t = y_t - y_{t-1}$. In other words, $y_{t-1}$ is treated as a predictor variable that has a coefficient fixed at a value of 1, and thus is treated as an "offset" and subtracted from both sides of the equation before fitting. I want to confirm that the assumption of "strict exogeneity", as described by Mathworks Here, also applies when a coefficient is not associated with "autoregressive" term.
3) The biggest difference, to me, when fitting with MLE vs. OLS is that in the MLE format I do not take the first difference of $y$ ahead of time, and $y_{t-1}$ is actually the predicted value from previous time step, not the observed value. Is this difference meaningful in distinguishing the OLS from MLE? It seems like it affects the interpretation of the error term, as a large innovation at time t will propagate to the next time step (I know this is poorly worded, but hopefully clear enough to understand my meaning). Also, I'm looking for a reference similar to the above OLS Mathworks link for describing the assumptions and consequences of violating those assumption when fitting with MLE.
Any assistance in answering these questions or links that point me in the direction of digestible reading would be greatly appreciated; thank you.
Answer: A quick remark: OLS and RE estimators in dynamic models are inconsistent. Since $y_{it}$ is a function $\alpha_i$ and $\alpha_i$ is constant over time $y_{i,t-1}$ is likewise a function of $\alpha_i$. One of the regressors ($y_{i,t-1}$) is correlated with the error term which leads to biased and inconsistent estimators. This bias in turn depends on the assumption about the initial condition. The way forward might be to look for an alternative approach (transformation of the equation) which eliminates the individual effects but which leads to consistent estimates at the same time  (for example the IV estimator of Anderson and Hsiao).
Comment: Under some circumstances, OLS can still be consistent estimator even if the expanatory variables are lags of the dependent variable. In particular, if the explanatory variables (considered random variables,not fixed) are contemporaneously uncorrelated with the disturbance $\epsilon_t$, $E(X_t\epsilon_t)=0$, then OLS is consistent and inference is valid in large samples. For some details see for example
[this post](http://stats.stackexchange.com/questions/133757/arq-model-with-f-test/133805#133805).
Comment: In this case, we don't have information about $X_{t-1}$ to see if it is correlated with $\epsilon_t$. Note that $y_{t-1}$ is not an issue, there is no coefficient attached to $y_{t-1}$, the dependent variable is actually $\Delta y_t=y_t - y_{t-1}$.
Comment: The question does not mention panel data, and your answer applies only to panel data.


Is the shortest line between two smooth arcs normal to both arcs?

Question: Ok, this seems obvious to me, but how would one prove it?
Let $<f(t),g(t)>$ and $<h(t),p(t)>$ be parametrized arcs in the cartesian plot. If $f,g,h,p$ are all continous and the arcs don't intersect, then there will be a line between the two that will be the shortest distance. Prove this line is normal to both arcs.
Is this proof non trivial? It seems so obvious, but i am not sure how it would be done.
Comment: The shortest distance between two non-adjacent sides of a regular pentagon is not normal to either.
Comment: @dxiv Pentagons are not smooth arcs.
Comment: Each side of a pentagon is though/
Comment: What does cont mean?  Constant?
Comment: @arkeet Line segments *are* smooth arcs.
Comment: @dxiv I suppose there is a smooth parametrization of a pentagon. But it would have to have zero derivative at each vertex.
Comment: @arkeet He is not talking about the whole of a pentagon, but rather about sides (which are line segments) of a pentagon.
Comment: @arkeet I was talking about the individual sides of the pentagon, not the polygon as a whole. Anyway, see my just posted comment under Fimpellizieri's answer. It looks like both you and the OP have some hidden assumptions about the parametrization which you haven't spelled out.
Answer: If you assume that the two curves are defined over an open interval, and there is a shortest segment connecting the two curves, then yes; just differentiate the squared length of the joining segment by one of the two parameters.

Okay, let me be more explicit.
I assumes that the two smooth curves $\alpha:I\to \mathbb{R}^2, \beta:I\to \mathbb{R}^2$ defined over an open interval $I\subseteq \mathbb{R}$ are given. For the sake of convenience, I write the component as $\alpha(t)=(\alpha_1(t),\alpha_2(t))$ etc. If we assumes that the two curves never meet and there exists a shortest line segment(which is not necessarily unique) joining the two curves, and the endpoints of the shortest segment be $\alpha(t_0)$ and $\beta(s_0)$. We can think of the squared length function $f: (t,s)\mapsto |\alpha(t)-\beta(s)|^2=(\alpha_1(t)-\beta_1(s))^2+(\alpha_2(t)-\beta_2(s))^2$, which is smooth by the assumption. Then as $(t_0,s_0)$ is a minimum point of this function, the derivative of $f$ at $(t_0,s_0)$ should be zero. Thus $2(\alpha_1(t_0)-\beta_2(s_0))\alpha_1'(t_0)+2(\alpha_2(t_0)-\beta_2(s_0))\alpha_2'(t_0)=0$, and similarly for $\beta'(s)$. This is exactly the condition that the segment is normal to the two curves.
Note that the assumption that the curve is defined over an open interval is necessary in this proof because the derivative may not be zero if there is a end point in the domain of the curves.
Comment: The original question doesn't mention differentiability, just continuity. Anyway, think of two disjoint arcs on the same circle. If considered as closed curves i.e. including their endpoints, there is always a shortest segment connecting them, but it won't be normal to either in general.
Comment: This still does not address the problem of a parametrization like dxiv's for line segments even. Perhaps if one furthermore requires the parametrization to be injective then it might be true.
Comment: @dxiv (and Fimpellizieri) It seems this post has been changed several times, but I'm assuming smoothness as the title did assume it. And I also assumes that the two curves are defined over open interval, so its closure it not necessarily the same as the original curve. I think the statement the OP wants is just what I wrote down.
Comment: I think the OP wanted to apply your statement to a more general scenario, but without proper care with the assumptions it is simply not true.
Comment: @Fimpellizieri Well then my answer should be negetive. Need to call the OP and settle down the question right now :)
Comment: @cjackal This looks good, with (and only with) the additional assumption that $\alpha(I), \beta(I)$ are open sets (for which a sufficient condition is $\alpha, \beta$ injective).
Comment: @dxiv Oh, by curves I mean a embedding of an interval into $\mathbb{R}^2$. We don't usually consider a mapping that has self-intersections for example as a curve, right?
Comment: `We don't usually consider a mapping that has self-intersections for example as a curve` Which is to say that you assume $\alpha, \beta$ to be injective.
Comment: @dxiv So I did assume the curves are embeddings, that's just definition.
Comment: @dxiv BTW, it seems extremely weird to me to read the OP's assumption as the two curves does not intersect but each curve can have self-intersection.
Comment: Guess it depends on context and background. To me a [Lissajous curve](https://en.wikipedia.org/wiki/Lissajous_curve) definitely counts as a smooth curve, for example, even though it both self-intersects and self-overlaps (many times, with the usual parametrization). Anyway +1 for answering the question that the OP most likely meant to ask, but couldn't quite articulate ;-)
Answer: This is not true; consider when the shortest line segment between them contains one of an arc's endpoints.
Comment: True, but assume t ranges from - infinity to positive infinity, then the arcs have no endpoints
Comment: This also means there may not be a shortest distance.
Comment: So maybe assumptions like the curves are infinitely extended should be necessary.
Comment: @LostStudent Infinite range of $t$ does not mean "*no endpoints*". For example $(x_0 + (x_1 - x_0)\cos^2 t, y_0 + (y_1-y_0)\sin^2 t)$ is the line segment between $(x_0,y_0)$ and $(x_1, y_1)$.
Comment: Even if the curves extend to infinity, there may be no minimum distance: consider the curves $(t,e^t)$ and $(t,0)$.
Answer: (The following is more of a comment on the context and intuition behind the result, rather than a formal answer - which has been largely provided by @cjackal.)
Starting with a restatement of the problem: let $C_1, C_2$ be two smooth curves in the $2D$ plane. Assume that, among all segments $AB$ with $A \in C_1, B \in C_2$, there exists a shortest one $PQ$. Further assume that the endpoints of this segment are interior points of the respective curves i.e. $P \in \text{int} \;C_1, Q \in \text{int}\;C_2$. Then $PQ$ is normal to both curves at the points of contact, which is equivalent to the tangents at $P,Q$ respectively to $C_1,C_2$ being parallel.

The smoothness assumption ensures that normality and tangency are well defined.
The existence of $P,Q$ is a necessary assumption since a shortest segment does not always exist, even for bounded curves. For example, there is no shortest distance between open segments $(0,0)$ and $(1, 0)$ on the real axis.
The assumption that $P,Q$ are interior points is required to eliminate cases where the minimum distance would be otherwise achieved at an endpoint of either curve. For example, the shortest distance between two closed segments which are not parallel does exist, but is not normal to at least one of them.
 (As a side note, the interior assumption is slightly more general than the assumption of $C_1,C_2$ being non-self-intersecting and open used in @cjackal's proof, for example it includes the case of two circles, but that proof itself could be adjusted fairly easily to relax those assumptions.)

Now back to the problem itself, draw the tangents at $P,Q$ to the respective curves. Since $P,Q$ are interior points, each has an open vicinity on the respective curve. For small enough such vicinities, they will each be on opposite sides of the respective tangents, and for infinitesimally small such vicinities the tangents  virtually approximate the curves around the two points. If the tangents are not parallel, then slightly shifting the points towards the intersection of the two tangents would yield two new points $P',Q'$ with $|P'Q'| \lt |P Q|$ but that would contradict the assumption of $P,Q$ being the shortest distance. Thus the tangents must be parallel, and $P Q$ must be normal to both.


Change background image by pressing a menu item in android

Question: Im creating simple notepad app in android,in options menu i have the "change background" as a menu item,when user clicks it,i just want to change the background image only [for example,i want to change my background image from efil tower to tajmahal],i have 10 images in drawable..how to change it randomly when everytime user clicks the "change background" option.Thank you.
Comment: can you please post some code ?
Comment: Provide the code or approach you tried so far?
Comment: i post my codes in pastebin.com my activity [link](http://pastebin.com/Skq5PCaN) and my layout [link](http://pastebin.com/pa9KhYms)
Answer: <code>int images[] = {R.drawable.eifel,R.drawable.tajmahal};
LinearLayout backLayout;

onCreate(Bundle savedInstanceState) {
   backLayout = (LinearLayout) findViewById(R.id.mybackgroundlayout);
}

private void changeBackground(){
 backLayout.setBackgroundResource(images[randInt(0,images.length-1)]);
}

public static int randInt(int min, int max) {
 Random rand = new Random();
 int randomNum = rand.nextInt((max - min) + 1) + min;
 return randomNum;
}

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    switch (item.getItemId()) {
    case R.id.changebackground:
        changeBackground();
        break;
    }
    return true;
}
</code>
Comment: Errors are,Multiple markers at this line
 - images cannot be resolved or is not a field
 - randInt cannot be resolved to a variable
 - Syntax error on token ",", . expected
 - Syntax error, insert ")" to complete Expression
 - The method setBackgroundResource(int) in the type View is not applicable for the arguments
  (Drawable)
Comment: when i tried this code 'backLayout.setBackgroundResource(getResources().getDrawable(images[randInt[0,images[].length]]));' ..it shows red underline in brackets
Comment: i have edited the answer.. you just need to add a missing ")" brace.try the changed answer
Comment: ok,now error is gone but i cant able to add return true; after the break statement.
Comment: edited again..try it..Are you new to android and Java ?
Comment: if you know java you must know how switch statement works.anyways i have edited the code..try it out
Comment: yes, u r ryt john,i know how switch statement works..but u dont understand my problem i think..it shows error in changebackground method and switch statement randomly,now it shows error in backlayout.setBackgroundResource(getResources().getDrawable(images[randInt(0,images.length)])); i can understand logic @john
Comment: now app force closes john,can u see my activity code i posted..then u can understand my problem.when i click "change background" in menu item,my activity force closes
Comment: can you post the logcat output ? of the crash
Comment: can u understand it john,it is so long i cant able to understand whn i pasted in notepad...log cat crash [link](http://pastebin.com/tP1J9LYQ)
Comment: its an array out of bound exception ...i have edited the answer ..try it..added -1 in changebackground..
Comment: john,it didnt work,can u tell how to change it through styles.xml..coz i tried more methods by java code,again and again it fails..i think it can be done by xml
Comment: whats is the issue with this code.. is your background not changing  or is there any crash ?
Comment: And more over styles are used to change the theme of whole application and colors
Comment: Background not changing john
Comment: I have only two activities...i want to change the background image randomly in my second activity @john


How do I add body class on specific content_type who have specific field?

Question: I need to add class in body when content type article and have image on it.
How do I achieve this?
I checked in theme_preprocess_html only found content_type as string. Don't know how to check image on it.
Answer: You will need to do a little work in the html preprocess:
/**
 * Implements template_preprocess_html().
 */
function mytheme_preprocess_html(&$variables) {
  $variables['has_image'] = FALSE;
  if ($variables['node_type'] == 'article' && ($node = \Drupal::routeMatch()->getParameter('node')) && $node instanceof \Drupal\node\NodeInterface) {
    $variables['has_image'] = empty($node->field_image->value) ? FALSE : TRUE;
  }
}

and the html template:
{#
/**
 * @file html.html.twig
 */
#}
<!DOCTYPE html>

...

This will add the class has-image to the body tag of every Article type content node.
Comment: Little addition: for media files use: `$node->field_image->entity`
Comment: Thanks it works on normal fields. I just alter the solution. I uploaded mine just in case.
Answer: In case you don't want to touch your template file.
/**
 * Implements hook_preprocess_html().
 */
function mytheme_preprocess_html(&$variables) {
  if ($variables['node_type'] === 'article') {
    $node = \Drupal::routeMatch()->getParameter('node');
    if ($node->field_image->getValue()) {
      $variables['attributes']['class'][] = 'has-image';
    }
  }
}


WSDL Client from Intellij generated code

Question: I am trying to make a client connect to a web service and use a SetFlight method on the server.
The environment is Intellij Ultimate, Java 7, and JAXWS. The generation of the classes from the WSDL has been done.
Among the generated classes I have two services:
<code>@WebServiceClient(name = "FOService", targetNamespace = "http://temporaryuri.org.au/", wsdlLocation = "http://fovanil.com/FOService.svc?wsdl")
    public class FOService
    extends Service
        {

        private final static URL FOSERVICE_WSDL_LOCATION;
        private final static WebServiceException FOSERVICE_EXCEPTION;
        private final static QName FOSERVICE_QNAME = new QName("http://temporaryuri.org.au/", "FOService");

            static {
...
</code>
And the IFO service
<code>@WebService(name = "IFOService", targetNamespace = "urn:fo.com.au/schema/common")
@SOAPBinding(parameterStyle = SOAPBinding.ParameterStyle.BARE)
@XmlSeeAlso({
    ObjectFactory.class
})
public interface IFOService {

    /**
     *
     * @param parameters
     * @return
     *     returns svc.SetFlightResponse
     */
    @WebMethod(operationName = "SetFlight", action = "http://fo.com.au/SetFlight")
    @WebResult(name = "SetFlightResponse", targetNamespace = "urn:fo.com.au/schema/common/types", partName = "parameters")
    public SetFlightResponse SetFlight(
        @WebParam(name = "SetFlightRequest", targetNamespace = "urn:fo.com.au/schema/common/types", partName = "parameters")
        SetFlightRequest parameters);

}
</code>
I have looked at some examples of implementing a client https://docs.oracle.com/javaee/5/tutorial/doc/bnayn.html however this differs.
I would have thought using this would be:
<code>IFOSerice service = new IFOService();
service.SetFlight(someinstanceofflight); //setFlight is not a available method
</code>
How do I make a client and use the SetFlight method?
Comment: How did you generate the classes from the WSDL? WHen using CXF to do this I need to tell it to generate the client implementation vs server implementation. Unfortunately I am not very familiar with Intellij in this area.
Answer: This code worked:
<code>    SetFORequest request = new SetFORequest();
    SetFOResponse response = new SetFOResponse();
    request.setFO(flight);
    FOService foService = new FOService();
    IfoService ifoService = foService.getWSHttpBindingIFOService();
    ifoService.setFO(request);
</code>


Normal distribution in R: Find the value of $x$ for $P(X=x) = c$ where $c$ is known

Question: I have a normal distribution with parameters $\mu=750$, $\sigma=260$. I'm interested in finding the value of $x$ that satisfies $P(X=x)=0.001$ for both sides of the tail. How would I go about doing that in R? I'm familiar with the dnorm and qnorm commands but I'm not sure how to implement them.
Eventually I'd like to expand this to distributions that aren't normal, so the more general the solutions are (ie: not using Z-score) the better.
Answer: Note that for any continuous random variable $P(X=x)=0$. But in your case if you are interested in mathematical view (not statistical)
$$
f(x)=\frac{1}{\sqrt{2\pi}\sigma}e^{\frac{-1(x-\mu)^2}{2\sigma^2}}
$$
just find the inverse of the function
$$
{x}=\mu+\sqrt{-2\sigma^2\log({\sqrt{2\pi}\sigma}f(x))}
$$
PS: this is just playing with an equation and there is no probability concept behind!
Comment: user81182 -- it's not just some obscure technical objection; density is *not* probability. Leave R aside for the moment -- what are you trying to achieve?
Comment: It sounds to me like you want to invert the cumulative distribution function, NOT the density.  I think you want to know the value of x such that P(X <= x)  = 0.001, and the value of x such that P(X <= x) = 0.999. If I am correctly discerning what you really want, then the answer to which I am commenting is NOT what you want. I believe part of the confusion is because little f, i.e., f(x), is traditionally used for probability density function, and capital F, i.e., F(X), is traditionally used for cumulative distribution function. I believe you want to deal with F(X), not f(x).
Comment: I believe that gives me the result from the cumulative, or $P(X<x)=.001$...

And yes, good point about how at any one spot technically the probability is 0.
Comment: I want the two values of $x$ that will give me $f(x)=0.001$.
Comment: So if I want to generalize this to other distributions, I should start with the pdf and algebraically work my way back to find the inverse, as you did above with the normal. Correct?
Comment: yes. But PLEASE notice that this is just mathematics and you cannot find probability density function in a single point  except you have a discrete RV.


Have these "calculus-based" consecutive summations been discovered yet?

Question: Consider the sum-of-powers series
$$S_i(n) = 1^i + 2^i + \cdots + n^i = \sum_{k=1}^n y_i(k) \quad\text{with}\; y_i(x)=x^i \tag{1}$$
For $i=1, 2, 3$, it turns out that we can write
$$\begin{align}
S_1(n) &= \frac{n+1}{n}\cdot\int_0^{n}y_1(x)\,dx \tag{2a}\\[4pt]
S_2(n) &= \frac{n+1}{n}\cdot\int_0^{n}y_2(x)\,dx \cdot \frac{y_2^\prime(n)+1}{y_2^\prime(n)} \tag{2b}\\[4pt]
S_3(n) &= \left(\frac{n+1}{n}\right)^2\cdot\int_0^{n}y_3(x)\,dx \tag{2c}\\[4pt]
\end{align}$$
which simplify to the well-known formulas
$$\begin{align}
S_1(n) &= \frac12 n(n+1) \tag{3a}\\[4pt]
S_2(n) &= \frac16 n(n+1)(2n+1) \tag{3b}\\[4pt]
S_3(n) &= \frac14 n^2 (n + 1)^2 \tag{3c}\\[4pt]
\end{align}$$
The only thing is that I'm not quite sure why these relations can include derivatives and integrals and somehow even work at all - they were simply a result of an extremely tiresome trial and error process. And can this "template" be extended to any $S_i(n)$ series or even more unorthodox variants?
Credits for the condensation and formatting of my answer goes to Blue (in the comments)
Comment: The [Euler–Maclaurin formula](https://en.wikipedia.org/wiki/Euler–Maclaurin_formula) might be of interest in this context, it describes the connection between the sum $\sum_{i=0}^n f(i)$ and the integral $\int_0^n f(x) dx$
Comment: @MartinR I just had a quick look and I think I might need to spend more time decrypting the logic, since the terminology is much more complex than I can possibly understand. But thanks for pointing me in the right direction!
Comment: By the way, the name for the general formula for these sums is called Faulhaber's formula. https://en.wikipedia.org/wiki/Faulhaber%27s_formula
Answer: (Too long for a comment.) The reuse and ambiguity of symbols is a little confusing. I'd like to try to restate the problem.

Consider the sum-of-powers series
$$S_i(n) = 1^i + 2^i + \cdots + n^i = \sum_{k=1}^n y_i(k) \quad\text{with}\; y_i(x)=x^i \tag{1}$$
For $i=1, 2, 3$, it turns out that we can write
$$\begin{align}
S_1(n) &= \frac{n+1}{n}\cdot y_1^\prime(n)\cdot\int_0^{n}y_1(x)\,dx  \tag{2a}\\[4pt]
S_2(n) &= \frac{n+1}{n}\cdot \frac{y_2^\prime(n)+1}{y_2^\prime(n)}\cdot\int_0^{n}y_2(x)\,dx \tag{2b}\\[4pt]
S_3(n) &= \left(\frac{n+1}{n}\right)^2\cdot\int_0^{n}y_3(x)\,dx \tag{2c}\\[4pt]
\end{align}$$
which simplify to the well-known formulas
$$\begin{align}
S_1(n) &= \frac12 n(n+1) \tag{3a}\\[4pt]
S_2(n) &= \frac16 n(n+1)(2n+1) \tag{3b}\\[4pt]
S_3(n) &= \frac14 n^2 (n + 1)^2 \tag{3c}
\end{align}$$
[Can this technique be extended? Is it new? etc, etc, etc]

Does this capture the intent of the question?
(BTW: I think you need to be a bit more explicit about why the relations in $(2)$ hold.)
Comment: @JainamShah: Your question is now clear on where you need help. As Martin suggests, Euler seems to have beaten you to this kind of analysis. (Euler has probably beaten *most* mathematicians to *something*.)
Comment: Gotta give it to him - Euler has not left a single stone unturned. Ah, I tried.
Comment: Thank you Blue for restating my question much more simply - I'm new on this platform so am still learning how to use the syntax. Would you mind completing your edit for the bit that I've added, and I'll replace my text with yours. Is that okay? Thanks again!
Comment: Sure. I just noticed you added the case for cubes. Give me a minute.
Comment: You are amazing - thanks a lot!
Comment: Thanks. :)  The update is complete. As noted, you really need to explain why the relations in $(2)$ hold.
Comment: That's the thing - I myself don't know how it works! All I did was make a table that included the sum at certain intervals, derivatives and integrals and then tried to find some proportionality between the terms, and it worked! That's why I'm so desperate to find out *why* it works at all.


Save Data in a Column Python DS18B20

Question: My Python code for data saves data of a temperature sensor(DS18B20) but doesn't save the Temperature in a column. The Temperature is written in a line like that: ['25.25']. Can somebody please tell me how to fix it. I have to separate the read Temperature from the Sensor into several Numbers. Thanks for your help
<code>    while programmStatus == 1:
    #while True:
            now = datetime.now(timezoneBerlin)

#while True:
    # open new file
            with open ( 'test.tsv', 'w') as f:
                for temperature_single in Temperature:
                    f.write ("{:>5}\n".format('Temperature'))
                    f.write("\t{:>5}\n".format
                    (format(temperature_single)))
                    f.write("\n")
                    f.flush()
                    f.close()

                x = 0
                ds1820readout()
                print ("Sensorname und Temperaturevalue:")
                while x < tempSensorQuantity:
                    print (tempSensorName[x] , " " , tempSensorValue[x], " °C")
                    x = x + 1
print ("\n")
</code>
In this code, there is an I/0 error on closed file, can somebody please help?
Comment: Please provide a very simple sample input and expected output, like [10.12, 12.15, 15.30] -> [10,12,30]
Comment: I will do this soon thanks
Comment: @Andreas I did this now and the Input (10.12, 12.15, 15.30) put in in the known code get the following output: 10.12 can anyone help me why its not write the next number in one line?
Comment: I would, but your question is unfortunately not really specific. You propably can delte most of your code from the question because it is very  distracting from your real problem. As far as I understand you have some sensor data. Please provide an copy paste example of what a sensor data can look like. And what your expectedt results from that input would look like. We can then work on how to get from the input to the output. Mabe a look at [mre] can help. Because currently your problem is neither Minimal, Complete nor Reproducible.
Comment: I´m so sorry about that, now it should be minimal. I will complete and reduce it soon :-)
Comment: A few issues to fix: a python code without correct indentation won't work. I guess your "with" is in your ds1820auslesen function, and not in that global stuff. Maybe use spaces everywhere for the forum (mixed tabs and spaces are bad). Also, your ds1820auslesen() function is called recursively with no way to exit. Lines below that won't run. Probably your .tsv is a tab separated vector, your function doesn't output anything like that. You used format twice for Temperatur. Why? Do you want to keep previous values? Opening the file in 'w' mode will delete them (use 'a', and forget the header).
Comment: Your "{:>5}\n".format('Temperatur') could be replaced by 'Temperatur'. Also, using english names is a better idea for a forum like this. Please describe what you'd like to achieve. From your code it's not clear to me.
Comment: At first, I appreciate your feedback. Should i write: " with open ( 'test.tsv', 'a') as f:" to keep the values saved in the tsv? Other things you mentioned I will be fixing soon thx.
Comment: @Nyos English names were added/edited. I want to achieve that the Temperaturevalue of my temperature Sensors were saved in tsv. So I can read out the temperature with timestamps an add some graphs in Excel
Comment: @florianvb could you please show some example data? You wrote: "The Temperature is written in a line like that: ['25.25']" How should it look like if it would be correct?
Comment: @Andreas The Temperature is written like :"['25.25', '26.00']" but It should be 25.25 next line 26.00
Comment: @florianvb could you provide a sample csv?  Is :"['25.25', '26.00']" written in the csv in the first line? if yes has it the: " or did u add them?
Comment: Why don't you put different sensors into different columns, and the next values into next line? Maybe start lines with a timestamp, so your Excel can create graphs.
Comment: @Nyos the program already wrote the temperature in the document and to put the data into different columns is exactly my problem
Answer: It seems that Temperature is a list of values. If you try to put them into the csv you have to iterate over the list first, e.g.:
<code>tempSensorName = []
tempSensorQuantity = 0
tempSensorValue = []
programmStatus = 1
Temperature = tempSensorValue

def ds1820einlesen():
    global tempSensorName, tempSensorQuantity, programmStatus
def ds1820auslesen():
    global tempSensorName, tempSensorQuantity, tempSensorValue,
            with open ( 'test.tsv', 'w') as f:
                for temperature_single in Temperature:
                    f.write ("{:>5}\n".format('Temperature'))
                    f.write("\t{:>5}\n".format(format(temperature_single)))
                    f.write("\n")
                    f.flush()
                    f.close()

                    x = 0
                    ds1820auslesen()
                    print ("Sensorname and Temperaturevalue:")
                    while x < tempSensorQuantity:
                        print (tempSensorName[x] , " " ,
    tempSensorValue[x], " °C")
                            x = x + 1
    print ("\n")
</code>
Comment: Thank you for the answer! But unfortunately, there is an I/O operation on closed file.
Comment: @florianvb could you share a sample file? I mean you could just use pandas to load the csv do the transformation on a pandas.DataFrame() and then export it as .tsv again.
Comment: what do you mean with Pandas? My editor is Thonny on raspberryPi
Comment: @florianvb pandas is a library which you would need to import. The thing is it is extremly complicated to debug something if you dont have a sample data set.

Save Data in a Column Python DS18B20


Bland-Altman with non-normally-distributed differences and "0" values in one of the two series of measurements

Question: I have two series of measurements of the same variable, coming from two different methods. The variable is represented by the weekly intake of a contaminant through diet. One method is a Food Frequency Questionnaire (FFQ), while the other is the measurement of a biomarker of exposition in the same individuals that answered the questionnaire. I want to evaluate the agreement between the two methods via Bland Altman analysis.
Before to run the analysis, I have checked the normality of the differences between the two methods (as recommended in https://pubmed.ncbi.nlm.nih.gov/26110027/) with Shapiro-Wilk normality test, and I discovered that the differences are not normally distributed. So I decided to log-transform both the series of measurements. The "problem" is that the measurements coming from the FFQ include some "0" values, and this because some participants answered that they consume none of the foods that contanin the contaminant. These same participants, however, have a value that is greater than "0" in the biomarker measurements (in other words, for some participants the intake of the contaminant inferred from the FFQ was "0", while the intake inferred from biomarker measurement was grater than 0).
How can I deal with the non-normality of differences, without losing the individuals that have "0" in the measurement series from the FFQ?
I tried to add a costant value to every values of both the series of measurement and then to log-transform, but I don't know if it is a proper way to deal with the issue.
Can anyone help me?
Comment: This is an old question, but still of interest to many I guess. On your last point, log(y + c) does divide opinion because how do you choose c? But more generally, it's hard to advise without seeing the data yet (1) people with 0 on one measure should not be excluded (2) other transformations might help (3) bootstrapping what you want to estimate could get round any normality assumption.
Answer: In the Bland-Altman method the log-transform is only designed to deal with some types of non-normal distribution, not all.
Read the original papers from 1986 and 1999: https://pubmed.ncbi.nlm.nih.gov/2868172/ and https://pubmed.ncbi.nlm.nih.gov/10501650/.
These give other ways to deal with non-normal differences. If the differences look very non-normal, the best way is probably the non-parametric method in the 1999 paper.
These papers also recommend judging whether the differences are normal based on eyeballing the scatter-plot and histogram, not a statistical test for normality.
Comment: Thank you. I also found this paper (https://www.mdpi.com/2571-905X/3/3/22). So, if I understand well, shall I use the 2.5% and 97.5% percentiles of the distribution of the differences as limits of agreement?
Comment: Have you read the two papers that I mentioned? If not, read them carefully and follow their advice. The first step is to look at the scatterplot and histogram. Depending on the patterns they show, you might decide to use the non-parametric method with the 2.5% and 97.5% percentiles, or you might decide to use a different method.


LINQ statement as if condition

Question: I saw a piece of code which was written like this:
if (from n in numbers select n where n = 5)

However, I tried writing something like this but came across errors (bare in mind the code sample may not be exactly as above as I am typing from memory). How can I write code like the above?
Thanks
Answer: In order to use this as a condition, you need to have an expression that returns a boolean.  Most likely, this means checking to see if there are any numbers that meet your criteria.
You probably wanted to do:
if ( (from n in numbers where n == 5 select n).Any() )
{
   // Do something
}

Personally, I'd avoid the language integrated syntax, and write this as:
if (numbers.Where(n => n == 5).Any())
{
   // Do something
}

Or even:
if (numbers.Any(n => n == 5))
{
   // Do something
}

Answer: It was probably something like this:
if ((from n in numbers where n == 5 select n).Any())

This can also be written as
if (numbers.Any(n => n == 5))

It is possible, but highly unlikely, that the code was actually
if (from n in numbers where n == 5 select n)

and numbers was a custom non-enumerable type with a Select method that returns bool.
Answer: if requires boolean expression.
Try with boolean expression in select part.
Comment: Wrong.  That would return `IEnumerable`.

LINQ statement as if condition


Question about proof of n-th orthogonal group

Question: In the book of Abstract Algebra I'm seeing there is an example of a group, $Ort_n(\mathbb{R})$ which is the group of all orthogonal endomorphisms in $\mathbb{R^n}$, all endomorphisms $f: \mathbb{R^n} \rightarrow \mathbb{R^n}$ such that $||f(u)|| = ||u||$ for all $u \in \mathbb{R^n}$ with the operation composition.
When proving that this indeed is a group, in order to show that $f \in \mathbb{R^n}$ has an inverse in $Ort_n(\mathbb{R})$ the book proves that every $f$ is one-to-one, therefore it's an isomorphism, and then proves that it is surjective.

I don't understand why does $f$ being one-to-one imply that it is an isomorphism, and neither understand the proof of surjectivity. Any hints?
Comment: Since you are in finite dimension, the dimension of the kernel of an endomorphism and the dimension of the image of the endomorphism sum to the dimension of the domain space ($n$, here). So if your endomorphism is one-to-one, its range is a subspace of $\mathbb{R}^n$ of dimension $n$, so it is $\mathbb{R}^n$ in full, ie your endomorphism is surjective.
Comment: Which book are you referring to?
Comment: Got it, thanks!
Answer: $f(u)=0$ implies that $\|f(u)\|=\|u\|=0$ $Ker f=0$ since $f$ is linear it is injective. An injective linear map between finite dimensional vector space which have the same dimension is surjective and therefore bijective.
Comment: Seems obvious now, thanks!!! I need 5 minutes in order to accept your answer...


Error when installing ESSURVEY package in R

Question: I am trying to install the package "essurvey". But it is just throwing out error messages.
I am running Ubuntu 20.04 LTS and R version 4.1.2 (2021-11-01).
    > install.packages("essurvey")
Installing package into '/home/knut/R/x86_64-pc-linux-gnu-library/4.1'
(as 'lib' is unspecified)
also installing the dependencies 'curl', 'xml2', 'httr', 'rvest'

trying URL 'https://cloud.r-project.org/src/contrib/curl_4.3.2.tar.gz'
Content type 'application/x-gzip' length 793345 bytes (774 KB)
==================================================
downloaded 774 KB

trying URL 'https://cloud.r-project.org/src/contrib/xml2_1.3.3.tar.gz'
Content type 'application/x-gzip' length 283965 bytes (277 KB)
==================================================
downloaded 277 KB

trying URL 'https://cloud.r-project.org/src/contrib/httr_1.4.2.tar.gz'
Content type 'application/x-gzip' length 159950 bytes (156 KB)
==================================================
downloaded 156 KB

trying URL 'https://cloud.r-project.org/src/contrib/rvest_1.0.2.tar.gz'
Content type 'application/x-gzip' length 94357 bytes (92 KB)
==================================================
downloaded 92 KB

trying URL 'https://cloud.r-project.org/src/contrib/essurvey_1.0.8.tar.gz'
Content type 'application/x-gzip' length 73081 bytes (71 KB)
==================================================
downloaded 71 KB

* installing *source* package 'curl' ...
** package 'curl' successfully unpacked and MD5 sums checked
** using staged installation
Package libcurl was not found in the pkg-config search path.
Perhaps you should add the directory containing `libcurl.pc'
to the PKG_CONFIG_PATH environment variable
No package 'libcurl' found
Package libcurl was not found in the pkg-config search path.
Perhaps you should add the directory containing `libcurl.pc'
to the PKG_CONFIG_PATH environment variable
No package 'libcurl' found
Using PKG_CFLAGS=
Using PKG_LIBS=-lcurl
------------------------- ANTICONF ERROR ---------------------------
Configuration failed because libcurl was not found. Try installing:
 * deb: libcurl4-openssl-dev (Debian, Ubuntu, etc)
 * rpm: libcurl-devel (Fedora, CentOS, RHEL)
 * csw: libcurl_dev (Solaris)
If libcurl is already installed, check that 'pkg-config' is in your
PATH and PKG_CONFIG_PATH contains a libcurl.pc file. If pkg-config
is unavailable you can set INCLUDE_DIR and LIB_DIR manually via:
R CMD INSTALL --configure-vars='INCLUDE_DIR=... LIB_DIR=...'
--------------------------------------------------------------------
ERROR: configuration failed for package 'curl'
* removing '/home/knut/R/x86_64-pc-linux-gnu-library/4.1/curl'
Warning in install.packages :
  installation of package 'curl' had non-zero exit status
* installing *source* package 'xml2' ...
** package 'xml2' successfully unpacked and MD5 sums checked
** using staged installation
Package libxml-2.0 was not found in the pkg-config search path.
Perhaps you should add the directory containing `libxml-2.0.pc'
to the PKG_CONFIG_PATH environment variable
No package 'libxml-2.0' found
Package libxml-2.0 was not found in the pkg-config search path.
Perhaps you should add the directory containing `libxml-2.0.pc'
to the PKG_CONFIG_PATH environment variable
No package 'libxml-2.0' found
Using PKG_CFLAGS=
Using PKG_LIBS=-lxml2
------------------------- ANTICONF ERROR ---------------------------
Configuration failed because libxml-2.0 was not found. Try installing:
 * deb: libxml2-dev (Debian, Ubuntu, etc)
 * rpm: libxml2-devel (Fedora, CentOS, RHEL)
 * csw: libxml2_dev (Solaris)
If libxml-2.0 is already installed, check that 'pkg-config' is in your
PATH and PKG_CONFIG_PATH contains a libxml-2.0.pc file. If pkg-config
is unavailable you can set INCLUDE_DIR and LIB_DIR manually via:
R CMD INSTALL --configure-vars='INCLUDE_DIR=... LIB_DIR=...'
--------------------------------------------------------------------
ERROR: configuration failed for package 'xml2'
* removing '/home/knut/R/x86_64-pc-linux-gnu-library/4.1/xml2'
Warning in install.packages :
  installation of package 'xml2' had non-zero exit status
ERROR: dependency 'curl' is not available for package 'httr'
* removing '/home/knut/R/x86_64-pc-linux-gnu-library/4.1/httr'
Warning in install.packages :
  installation of package 'httr' had non-zero exit status
ERROR: dependencies 'httr', 'xml2' are not available for package 'rvest'
* removing '/home/knut/R/x86_64-pc-linux-gnu-library/4.1/rvest'
Warning in install.packages :
  installation of package 'rvest' had non-zero exit status
ERROR: dependencies 'xml2', 'httr', 'rvest' are not available for package 'essurvey'
* removing '/home/knut/R/x86_64-pc-linux-gnu-library/4.1/essurvey'
Warning in install.packages :
  installation of package 'essurvey' had non-zero exit status

The downloaded source packages are in
    '/tmp/RtmpWcvxK9/downloaded_packages'

I have tried installing both the curl package and libcurl4-openssl-dev,libxml2-dev. The curl package gives me the same non-zero exit status, and libcurl4-openssl-dev,libxml2-dev shows:
> install.packages("libcurl4-openssl-dev")
Installing package into '/home/knut/R/x86_64-pc-linux-gnu-library/4.1'
(as 'lib' is unspecified)
Warning in install.packages :
  package 'libcurl4-openssl-dev' is not available for this version of R

A version of this package for your version of R might be available elsewhere,
see the ideas at
https://cran.r-project.org/doc/manuals/r-patched/R-admin.html#Installing-packages

I hope I am missing something big here, I am new to programming in general.
Comment: you can find your answer [here](https://stackoverflow.com/questions/70953648/r-install-packages-languageserver-had-non-zero-exit-status/70954875#70954875)
Comment: From terminal install the package as: `$ sudo apt install libcurl4-openssl-dev`. THis part of error: `Configuration failed because libcurl was not found. Try installing:
 * deb: libcurl4-openssl-dev (Debian, Ubuntu, etc)` tells you what packatge is missing.
Comment: The same for  `libxml2-dev`: like `sapi@t5810:~$ sudo apt install libxml2-dev`
Answer: Grzegorz Sapijaszko answered my question with this answer:
From terminal install the package as: $ sudo apt install libcurl4-openssl-dev. THis part of error: Configuration failed because libcurl was not found. Try installing:  * deb: libcurl4-openssl-dev (Debian, Ubuntu, etc) tells you what packatge is missing.
The same for libxml2-dev: like sapi@t5810:~$ sudo apt install libxml2-dev
Thank you!


how to select distinct and concatenate in sql

Question: Lets say we have a following table with two columns and following rows of data  in SQLServer-2005:
Tiger    50
Wolf     4
Tiger    53
Lion     55
Elephant 54
Rhino    52
Lion     5

Can we have a sql query that result as following: Tiger,Wolf,Lion,Elephant,Rhino as a single string varchar output?Is it possible ?
using T-SQL not possible singe I am using the result in c# as a result of executescalar
Thank you in advance.
Answer: You can use for xml path to concatenate the values:
select distinct name + ', ' as [text()]
from @t
for xml path('')

-->
Elephant, Lion, Rhino, Tiger, Wolf,

Chop of the last 2 bytes if you don't like trailing ,'s.
Not sure why you can't use T-SQL, you can use this in combination with ExecuteScalar() just fine.
Sample data:
declare @t table (name varchar(max), id int)
insert into @t
select 'Tiger', 50
union all select 'Wolf', 4
union all select 'Tiger', 53
union all select 'Lion', 55
union all select 'Elephant', 54
union all select 'Rhino', 52
union all select 'Lion', 5

Comment: @Thunder: The second part is just your example data in T-SQL; the query with `for xml path` should work for any data
Comment: @Thunder: Yeah, `@t` is just the name of my table variable (it's not a real table but a table variable, so it starts with @.)  You can replace `@t` with the name of your table
Comment: @Thunder: It's a construct meant for generating XML output.  To use it for generating comma-seperated lists is something of a trick; it wasn't designed for that.  You can find more about the intended uses here: http://msdn.microsoft.com/en-us/library/ms190922.aspx
Comment: @Andomar We could have any data in first column so could not hard-code it.
Comment: @Andomar I think its correct but I already have table with data ,can we link @t to an existing table?
Comment: @Andomar Thanks Andomar ,It worked ! alo quite amazed this is very new to me.I have never come across "for xml path('')"  can u let us know what is this actually ,I am sure its not normal SQL
Answer: See How to return multiple values in one column (T-SQL)?
Comment: using T-SQL not possible singe I am using the result in c# as a result of executescalar
Comment: @Thunder, that doesn't make any sense, the only requirement for `ExecuteScalar` is that there is only one result.  There is no restriction whatsoever on what the SQL looks like before the final `SELECT`.  I'm upvoting this one.
Answer: Assuming you are getting this from ExecuteScalar and using the resulting composite string in C#, then you are going to end up writing a sproc, or just having your code work with the datatable.
Can you provide more detail on why you can't use a sproc?  A few good examples have been provided that would do fine with that, and you can still get your scalar result
Comment: Sored procedure could not be written as it would increase more process in deployment as we will have to add sproc to db manually
Answer: Use GROUP_CONCAT() with DISTINCT:
SELECT GROUP_CONCAT(DISTINCT colName) FROM tblName;

Comment: downvoting this because the example is in the wrong SQL dialect, and should not have been upvoted.
Comment: Group_concat works in MySQL, but the question is about SQL Server
Comment: @Crozin I think your answer is near to solution but GROUP_CONCAT was not recognised ,Please note that we are using sqlserver2005
Comment: Oh, my bad... I didn't noticed it's about sql-server-2005.
Answer: The most efficient way is probably to use a User-Defined Aggregate, but you can also abuse the UPDATE statement:
DECLARE @Result varchar(500)
SET @Result = ''

UPDATE Animals
    SET @Result = @Result + Name + ','

SELECT @Result

Answer: This is how Andomar's Answer was implemented.Thanks to Andomar's answer got to learn some thing new with this .

select distinct summaryColumn + ', '
  as [text()] from tablename for
  xml path('')


the path for phpmyadmin

Question: i have www doc in html folder. i go to 192.168.1.1/phpmyadmin to pull it up. but when i ftp there i dont see any phpmyadmin folder under html folder. how can i find where phpmyadmin folder is? i am using centos
Answer: You don't see any phpmyadmin folder when accessing your hosting via FTP because it's an alias, some kind of virtual folder.
If you have an SSH access to your hosting, phpMyAdmin is usually located in /usr/share/phpmyadmin. If you don't find it there, try to locate it :
<code>$ locate phpmyadmin
</code>
Answer: I've found that many distributions would rather install an application's web files within /usr/lib or /usr/share as a convention. As such, you may want to verify your apache configuration files to determine the exact path.
In this case, most likely you'll have the phpmyadmin apache directives within a file located within /etc/apache2/conf.d or /etc/httpd/conf.d or the like. The configuration file will have a  statement which will detail the location of your files.
Answer: It's probably in /var/www/html/phpmyadmin, but take a look at your Apache configuration files to make sure (try grepping for phpmyadmin in all your Apache config directories).
Comment: i tried $ > grep phpmyadmin. Is that correct?
Answer: On CentOS, check: /usr/share/phpMyAdmin
If not there, do a
<code>$whereis phpMyAdmin
</code>

the path for phpmyadmin