How can I migrate user profile content?

Question: I am using user_save() to migrate users from another application into Drupal, but my profile fields are not updating.
Does anyone have any suggestions as why this isn't working, or how I can get it to
        $newUser = array(
          'name' => $row->user_name,
          'pass' => $row->user_password, // note: do not md5 the password
          'mail' => $row->user_email,
          'status' => 1,

          'profile_title'=>$row->user_title,
          'profile_firstname'=>$row->user_first_name,
          'profile_lastname'=>$row->user_last_name,
          'profile_jobtitle'=>$row->user_job_title,
          'profile_orgname'=>$row->user_organization,
          'profile_telno'=>$row->user_contact_no,
          'profile_faxno'=>$row->user_fax_no,
          'profile_streetaddress'=>$row->user_address1.$row->user_address2,
          //'profile_address2'=>sanjay,
          'profile_city'=>$row->user_city,
          //'profile_state'=>sanjay,
          'profile_postalcode'=>$row->user_postal_code,
          'profile_country'=>$row->iso,
          //'profile_stateprovince'=>$row->sanjay,
          //'old_user_id'=> $row->user_id,
          'init' =>$row->user_initial,
        );
        user_save(null,$newUser);

Comment: which version of drupal you're using? how these user fields were created in drupal? can you show us a sample of your code?
Comment: i am using drupal 6
Answer: I think User import module can help you with that
Comment: no it don't its only for import not for migration.
Comment: yeah, but you can export a csv file from the old website and import it in drupal
Comment: i tried in this way also...
Comment: I usually do it this way: implement hook_user and print_r the $edit or $account object when inserting a new user from the interface. That way you'll see the exact structure of the user object and can construct your $newUser object based on that one.

How can I migrate user profile content?


A question about K-fold cross validation in the context of neural networks

Question: Let's say that I want to perform K-fold cross validation for a neural network model. So, as usual, I split my dataset D into $K$ different folds. The fold $k$ is the validation fold while the remaining $k-1$ are training folds. My question is: would it be correct to use the validation fold $k$ as validation set for the neural network, or would this lead to information leakage, if we, for example, use early-stopping or other training schemes that could bias the learning process towards the specific data in the validation? Personally, my approach so far has been extracting an additional 10% of data from the $k-1$ training folds to be used as validation set for the network, in a way that the validation fold remains completely untouched. Do you think that this approach would eventually be better?
Answer:
my approach so far has been extracting an additional 10% of data from the −1 training folds to be used as validation set for the network, in a way that the validation fold remains completely untouched.

I think that is the same as what I was going to say.
I would do ordinary k-fold and, within each of the k iterations, allocate some small percentage of the k-1 pool for early stopping. I would not reserve one of the k folds for any special purpose.
Doing it this way also properly cross-validates the early stopping; a different bit of data is used each of the k times, and any negative (or positive) effect of that will correctly propagate to the resampling statistics.
(This is exactly how we designed in R's tidymodels framework)
If you have a really large sample, then maybe keep a static early stopping validation set around. Otherwise, make sure to repeat the early stopping process k times with different data.


Facebook AppLink created from applinkshost

Question: I use UIActivityViewController for sharing content, code is pretty simple:
<code>  UIActivityViewController* activityViewController = [[UIActivityViewController alloc] initWithActivityItems:[feedCell activityItems]
                                                                                applicationActivities:nil];
  [self presentViewController:activityViewController animated:YES completion:NULL];
</code>
where activityItems are:
<code>- (NSArray *)activityItems {
  return @[self.titleLabel.text, self.titleImageView.image, [NSURL URLWithString:@"https://fb.m..234"]];
}
</code>
Can't figure out, is it possible to make an app link created from Facebook
App Links Hosting API has an thumb + install/open button?
I created one and it works great, but it has only a title and fb.me..:

My goal is to make it look like this:

Thanks for any help.
Answer: No, that does not seem to be possible. https://developers.facebook.com/docs/graph-api/reference/v2.7/app-link-host lists the fields an app link host object has – and there is no thumbnail.
If you want a thumbnail, then you have to add the App Links meta data to an existing URL: https://developers.facebook.com/docs/applinks/add-to-content With that, you can use all the other OG meta tags as well.
Comment: hi, tnx for the answer, I created a test url with meta tags, I tested it with uiactivityviewcontroller and it works fine: displays an image, title and description. But now it is a problem to attach an image, I read lots of posts and it seems like this is a well known problem, I tried to to make a post via slcomposerviewcontroller, fbsdksharedialog and as I wrote before uiactivityviewcontroller, but result is the same - if a attach an fb app link as a url, then there is no image in feed post..I would be grateful to if you have any ideas about it. Thanks anyway)
Comment: I attached an image via meta tags, it is an icon of an app, but I need to attach one more as a post with description


How to differentiate token replacement from array index

Question: How to escape left square bracket - [ and Right square bracket - ] when used in views so that it is not mistaken for a token.
I have what I hope is a simple question to answer. I have tried searching online but have been unable to find an answer (perhaps using the wrong search terms - I don't know). I am using Drupal 7 with views and the fillPDF module. I have modified one of the outputs of my view to use token replacement. The issue I am having is that the string that is being used for the token replacement has an array with an index that is the same as the token. Here is the code:
Create a PDF

As you can see, I need away to make sure webform[nid] and webform[sid] doesn't become webform1 and webform2 after token replacement. How do I accomplish this? There must be a way to escape the array.
Thanks.
Answer: You can escape the left square bracket - [ using - %5B
and Right Square Bracket - ] using - %5D
So you should change your code in question to the following.
Create a PDF

Comment: Remember to show the HTML as code.


On the pointwise limit of a sequence of probability generating functions, assuming this limit exists on [0,1].

Question: Suppose X_n (for each positive integer n) is a stochastic variable concentrated on the nonnegative integers. Suppose that the probability generating function P_{X_n}(t)= E(t^(X_n)) of X_n converges pointwise on the closed unit interval to a function g: [0,1] -> R. Under what conditions is g itself a probability generating function? Is it sufficient that g(t) is continuous from the left in t=1?
In other words, I am looking for the pgf-analogue of the continuity theorem of Levy-Cramer which says that if the characteristic function of X_n (not necessarily concentrated on nonnegative integers in this theorem) converges pointwise to a function g (on R) and if g is continuous in 0, then g is itself a characteristic function. Thanks a lot in advance!
Answer: $Et^{X_n}$ is same as $Ee^{-sX_n}$ where $s=-\log \, t$. Thus what you are asking for is a continuity theorem for Laplace transforms. This theorem is proved in Volume 2 of Feller's book. The condition is indeed continuity of $g$ from the left at $1$.
Comment: Thanks a lot! Do you also have an exact reference (i.e. page or theorem number)?
Comment: I did not give the theorem number because mine is Wiley Eastern edition. If you look at the contents there is a chapter on Laplace transforms and the very first section has the continuity theorem.


Binding a Telerik RadRibbonComboBox in C#

Question: Could you please help to fill a telerik RadRibbonComboBox item dynamically from C# code behind by the Binding.
I already done that in the XAML page by the below instructions, and now need to do it in the code behind ?
<telerik:RadRibbonComboBox Name="Cmb" SelectedIndex="0" IsEditable="False"  Width="98" Margin="0 2 1 2" SelectionChanged="CmbSelectionChanged">
<telerik:RadRibbonComboBoxItem Content="myContent" Tag="myTag" />

Regards
Answer: I think you can add attribute id and onitemdatabound.
<telerik:RadRibbonComboBox Name="Cmb" SelectedIndex="0" IsEditable="False"  Width="98" Margin="0 2 1 2" SelectionChanged="CmbSelectionChanged" id="myRadRibbon" onitemdatabound="myRadRibbon">

After that you can make function in c# code behind (or this function will generate automatically).
protected void myRadRibbon(object o, RadComboBoxItemEventArgs e)
{
    //bind
}

Comment: Thank you for your answer, now could you please give me an example on how to assign values to RadRibbonComboBoxItem Content and Tag properties.

Comment: If you define id you can call atttribute in code behind by this id. myRadRibbon.Content etc.
Comment: Please note that I'm working with _RadRibbonComboBox_ so I didn't found the _id_ and _onitemdatabound_ attributes as you describe previously !


Fitting a particular Gaussian model

Question: Using R or SAS, I want to fit the following Gaussian model:
$$
\begin{pmatrix}
y_{1j1} \\ y_{1j2} \\ y_{1j3} \\ y_{2j1} \\ y_{2j2} \\ y_{2j3}
\end{pmatrix}
\sim_{\text{i.i.d.}}
 {\cal N}
 \left(
 \begin{pmatrix}
\mu_1 \\
\mu_1  \\
\mu_1 \\
\mu_2 \\
\mu_2  \\
\mu_2
 \end{pmatrix}
 , \Sigma \right), j=1, \ldots n
$$
with covariance matrix having the following structure:
$$
\Sigma =
\begin{pmatrix}
\Sigma_0 & M \\
M & \Sigma_0
\end{pmatrix}
$$
with $\Sigma_0$ a "compound symmetry" (exchangeable) covariance matrix and $M=\delta \begin{pmatrix} 1 & 1 & 1 \\ 1 & 1 & 1 \\ 1 & 1 & 1 \end{pmatrix}$, $\delta \in \mathbb{R}$.
Importantly, I need a general exchangeable matrix $\Sigma_0$, with possibly negative correlation.
EDIT: In view of some comments (and even an answer) given below I should add a precision: I am not a beginner with PROC MIXED in SAS and nlme in R, and I know how to consult the documentations. But in spite of my experience I am not able to fit this model.
Comment: Obviously the question is: how to fit such a model with R or SAS ?
Comment: So what is your question?
Comment: So you wish to estimate a covariance matrix $\Sigma_0$ based on two dependent vectors with known inter-covariances. Is $\delta$ known?
Comment: All parameters are unknown.
Comment: There probably is a pre-existing package in R to fit this model (look into covariance structure models) but I don't know what it is - this seems more like the business of MPLUS. In any case, you can write down the likelihood, code it into R and maximize it using `optim` :)
Comment: I have look the nlme package but I have not find a way to specify such a correlation structure. I do not only need estimates of the parameters, but also the standard errors (for estimates of the means). Moreover I'm working in a private company, it is preferable to use a software.
Comment: I was trying to code it in R but I am intrigued because this covariance structure is not a positive definite matrix. For example if $\Sigma_0=I_3$ and $\delta=1$, then $\vert \Sigma\vert = -8$.
Comment: Thanks for this remark. Some restrictions are required on $\delta$.
Comment: So the standard `corCompSymm` for `nlme` does have the correct $\Sigma_0$ term but not 1 as $M$ and you want to know how to set $M$ to 1?
Answer: I think you may have to go for direct optimisation of the loglikelihood, especially if you want to allow negative correlations in the diagonal block. At least in R; I don't speak SAS.
I would follow what lme4 does in profiling out the $\mu$ terms and an overall scale factor and then feeding the -2 log profile likelihood to minqa::bobyqa, which is a fast, derivative-free optimiser for smooth functions.  That's what I've done for composite-likelihood mixed models.
The profile likelihood calculations are in the lme4 "Computational Methods" vignette.
Answer: You haven't told us how many data points you have.  You need a certain number for the parameters to be estimable.  I don't think that SAS has a proc that fits multivariate distributions per se but if you were using proc mixed and y is in the model  these parameters would be calculated and could be printed out. You would have to specify the covariance structure.
Comment: The question is: how to specify this covariance structure ?

Fitting a particular Gaussian model


Mostra imagem em JSP

Question: Estou tendo problema para mostrar uma imagem em minha página JSP. Estou tentando utilizar várias formas diferentes de pegar o arquivo e não consigo mostrá-lo na página.
As pastas estão dispostas da seguinte maneira
WebContent
|_1.jpg
|_ParaEmpresas.png
|_img
    |_1.jpg
    |_ParaEmpresas.png

O código na minha página jsp

<img src="<c:url value="/img/ParaEmpresas.png"/>" />
<img src="<c:url value="/ParaEmpresas.png"/>" />

e o erro ao tentar carregar a página
ADVERTÊNCIA: No mapping found for HTTP request with URI [/DataIdea/img/1.jpg] in DispatcherServlet with name 'springmvc'set 08, 2015 4:13:08 PM org.springframework.web.servlet.DispatcherServlet noHandlerFound

WEB.XML
<?xml version="1.0" encoding="UTF-8"?>

http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd" id="WebApp_ID" version="3.0">
    DataIdea
<welcome-file-list>
    <welcome-file>index.html</welcome-file>
    <welcome-file>index.htm</welcome-file>
    <welcome-file>index.jsp</welcome-file>
    <welcome-file>default.html</welcome-file>
    <welcome-file>default.htm</welcome-file>
    <welcome-file>default.jsp</welcome-file>
</welcome-file-list>
<resource-ref>
        <description>postgreSQL Datasource example</description>
         <res-ref-name>jdbc/postgres</res-ref-name>
        <res-type>javax.sql.DataSource</res-type>
         <res-auth>Container</res-auth>
    </resource-ref>
<servlet>
    <servlet-name>springmvc</servlet-name>
    <servlet-class>
        org.springframework.web.servlet.DispatcherServlet
    </servlet-class>
    <init-param>
        <param-name>contextConfigLocation</param-name>
        <param-value>
            /WEB-INF/spring-context.xml
        </param-value>
    </init-param>
    <load-on-startup>1</load-on-startup>

</servlet>

<session-config>
    <session-timeout>30</session-timeout>
</session-config>
<servlet-mapping>
    <servlet-name>springmvc</servlet-name>
    <url-pattern>/</url-pattern>

</servlet-mapping>
<error-page>
    <exception-type>java.lang.Exception</exception-type>
    <location>/WEB-INF/views/erro/erro.jsp</location>
</error-page>
<listener>
    <listener-class>br.com.quartz.ListenToMeFirst</listener-class>
</listener>

Comment: Qual a diferença de diretório da sua JSP e da img? Provavelmente você está informando o caminho incorreto, você pode confirmar no console do navegador se tiver dando `erro 404`
Comment: Você tem o servlet configurado para expor o diretório publicamente?
Comment: @BrunoCésar Eu já tinha tentado usando JSP Scriplet. Tentei usar JSTL e tambem não deu.
Comment: @flpms desculpa a minha ignorancia, mas como a aplicação é grande então e eu ser novo projeto eu não tinha mexido ainda no XML, por isso atualizei a pergunta com o código. Caso precise de alguma informação me avise
Answer: Uma solução que eu achei foi acrescentar esse código no WEB.xml
    <servlet-mapping>
    <servlet-name>default</servlet-name>
    <url-pattern>*.png</url-pattern>
    <url-pattern>*.jpg</url-pattern>
</servlet-mapping>

e fazer referencia à imagem utilizando a seguinte tag
<img src="<c:url value="….. "/>" />

Utilizando essa hierarquia na pastas
WebContent
|_img
    |_ParaEmpresas.png

O código ficaria da seguinte forma
 <img src="<c:url value="/img/ParaEmpresas.png"/>" />

Mostra imagem em JSP


How do I search by multiple keywords when using awk or grep?

Question: I have a collection of files.  I want to search through them all with grep to find all and only those which contain anywhere within them both the strings keyword1 and keyword2.
I would also like to know how to do this with awk.
Answer: For grep, the pipe symbol separates strings in a combination regexp; on some systems, it may be necessary to use egrep to activate this functionality:
[madhatta@anni ~]$ egrep 'exact|obsol' /etc/yum.conf
exactarch=1
obsoletes=1

I would expect the syntax to be similar for awk.
Edit: yup:
[madhatta@anni ~]$ awk '/exact|obsol/ {print $1}' /etc/yum.conf
exactarch=1
obsoletes=1

Edit 2:
You have clarified your request, so here's how to do it with grep:
grep -l keyword1 * | xargs -d '\n' grep -l keyword2

This will search all the files in a given directory (*) for keyword1, passing the list of matching files onto the second grep, which will search for the second string, via xargs.  I'm afraid I won't be bothering to do this with awk as it's beginning to sound a bit like a homework problem.  If you have a business case for using awk, let us know.
Comment: What I want is not `OR`, but `AND`
Comment: That's an ambiguous question.  Do you want a list of **files** that contain both keywords anywhere, or a list of files that contain both keywords on the same line, or all **lines** that contain both keywords from a single file?
Comment: It's the first case.
Comment: See Edit 2 above; also, I have edited your question to clarify your request.
Answer: Search in one file
Using grep to find lines with either "keyword1" or "keyword2" in the file "myfile.conf":
grep -e "keyword1\|keyword2" myfile.conf

The escaping of the pipe | character with a backslash is at least required in zsh.
Search in all files in a directory
To search for files containing either "keyword1" or "keyword2" in a directory:
grep -r -e "keyword1\|keyword2" /path/to/my/directory

If you want to do a case-insensitive search, add the -i option as well.
Answer: If I understand correctly, you want to search all the files which contains keyword1 and keyword2 in a specific folder, so, try this:
$ find /path/to/folder -type f -print0 | xargs -0 grep -li "keyword1" | \
                                    xargs -I '{}' grep -li "keyword2" '{}'

-print0 | xargs -0 take cares of file names with blank spaces
-I tells xargs to replace '{}' with the argument list
grep -li  prints file name instead of matching pattern. I use -i
for case insensitive.


process listing and it details

Question: hi sorry id for my qustion !
i write a code that show process in one list and it's detial's in onther and show madual
i read frist in c#2010 and work but i need it in c#2008 , in c#2008 i get
error" Access Denaid" and only show only ~5 of 45 process:(
<code> private string GetProcessOwner(int ProcessID)
    {
        string ProcessOwner = "";
            ObjectQuery ObjQuery = new ObjectQuery("Select * From Win32_Process where ProcessID=" + ProcessID.ToString());
            ManagementObjectSearcher MgtObjSrch = new ManagementObjectSearcher(ObjQuery);
        foreach (ManagementObject MgtObj in MgtObjSrch.Get())
            {
                string[] s = new string[1];
                MgtObj.InvokeMethod("GetOwner", (object[])s);
                if (s[0] != null)
                ProcessOwner = s[0];
                break;
            }
                return ProcessOwner;
    }

    public void getprocesses()//start function ..........
    {
        ListViewItem lstitm;
        lsvproccess.Items.Clear();
        int index = 1;
        //get total ram
        ManagementObjectSearcher searcher = new ManagementObjectSearcher("select * from Win32_ComputerSystem");
        foreach (ManagementObject share in searcher.Get())
        {
             RAMCapacityByte = Convert.ToInt32(share["TotalPhysicalMemory"]);
             RAMCapacityKB = RAMCapacityByte / 1024;
             RAMCapacityMB = RAMCapacityKB / 1024;
             RAMCapacityGB = RAMCapacityMB / 1024;
        }
        toolStripStatusLabel7.Text = RAMCapacityMB.ToString() + " Kb";// view total ram memory
        toolStripStatusLabel5.Text = Environment.UserName;//view user name login
        Int32 totalmemo = RAMCapacityKB;
        processes = Process.GetProcesses(); //trying to get local active processes
        try
        {
            foreach (Process pro in processes)
            {
                if (pro.ProcessName != "Idle")
                {
                    var wallTime = DateTime.Now - pro.StartTime;
                    if (pro.HasExited)
                        wallTime = pro.ExitTime - pro.StartTime;
                    var procTime = pro.TotalProcessorTime;
                    var cpuUsage = 100 * (procTime.TotalMilliseconds / wallTime.TotalMilliseconds);
                    var memousage = (pro.PrivateMemorySize64 / 1024);
                    if (Environment.UserName == GetProcessOwner(pro.Id) && wallTime.TotalMinutes > 60)
                    {
                        DialogResult result;
                        result = MessageBox.Show("Prossecc: " + pro.ProcessName + "\n" + "Total Time: " + wallTime.TotalMinutes.ToString("00000") + " Min\n",
                            "Are you will close it?", MessageBoxButtons.YesNo, MessageBoxIcon.Warning);
                        if (result == DialogResult.Yes)
                            pro.Kill();
                    }
                     if (cpuUsage > 1)
                    {
                        DialogResult result;
                        result = MessageBox.Show("Prossecc: " + pro.ProcessName + "\n" + "Cpu Usage: " + cpuUsage.ToString("0.000") + " Ms\n",
                            "Are you will close it?", MessageBoxButtons.YesNo, MessageBoxIcon.Warning);
                       if (result == DialogResult.Yes)
                            pro.Kill();
                    }
                     if (memousage > (totalmemo * 0.3))
                    {
                        DialogResult result;
                        result = MessageBox.Show("Prossecc: " + pro.ProcessName + "\n" + "Memo Usage: " + memousage.ToString() + " Kb",
                            "Are you will close it?", MessageBoxButtons.YesNo, MessageBoxIcon.Warning);
                        if (result == DialogResult.Yes)
                            pro.Kill();
                    }
                     if (Environment.UserName == GetProcessOwner(pro.Id) && pro.MainModule.FileVersionInfo.CompanyName == "Microsoft corporation")
                    {
                        pro.Kill();
                        MessageBox.Show("Prossecc: " + pro.ProcessName + "\n",
                           "Is Terminat!", MessageBoxButtons.OK, MessageBoxIcon.Stop);
                    }
                    else
                    {
                        lstitm = new ListViewItem();
                        // binding listview instance to desired attributes
                        lstitm = lsvproccess.Items.Add(index.ToString("000"));
                        lstitm.SubItems.Add(pro.ProcessName);
                        lstitm.SubItems.Add(pro.Id.ToString());
                        lstitm.SubItems.Add(wallTime.TotalMinutes.ToString("000000") + " M");
                        lstitm.SubItems.Add(cpuUsage.ToString("0.000") + " ms");
                        lstitm.SubItems.Add(memousage.ToString() + " kb");
                        lstitm.SubItems.Add(GetProcessOwner(pro.Id));
                        index++;
                        toolStripStatusLabel3.Text = index.ToString();// view total process
                    }
                }
            }
        }

        catch (Win32Exception exp)
        {
            MessageBox.Show(exp.Message, this.Text, MessageBoxButtons.OK, MessageBoxIcon.Error);
        }
    }

    private void Detail_process(Process p)//start function..............
    {
        lsvitems.Items.Add("ProcessName:").SubItems.Add(p.ProcessName);
        try
        {
            lsvitems.Items.Add("BasePriority:").SubItems.Add(p.BasePriority.ToString());
        }
        catch (PlatformNotSupportedException err)
        {
            lsvitems.Items.Add("BasePriority:").SubItems.Add(err.Message);
        }
        try
        {
            lsvitems.Items.Add("Handle:").SubItems.Add(p.Handle.ToString());
        }
        catch (Win32Exception err)
        {
            lsvitems.Items.Add("Handle:").SubItems.Add(err.Message);
        }
        try
        {
            lsvitems.Items.Add("Process Id:").SubItems.Add(p.Id.ToString());
        }
        catch (Win32Exception err)
        {
            lsvitems.Items.Add("Process Id:").SubItems.Add(err.Message);
        }
        try
        {
            lsvitems.Items.Add("MachineName:").SubItems.Add(p.MachineName);
        }
        catch (InvalidOperationException err)
        {
            lsvitems.Items.Add("MachineName:").SubItems.Add(err.Message);
        }
        try
        {
            lsvitems.Items.Add("MainModule:").SubItems.Add(p.MainModule.ToString());
        }
        catch (Win32Exception err)
        {
            lsvitems.Items.Add("MainModule:").SubItems.Add(err.Message);
        }
        try
        {
            lsvitems.Items.Add("MainWindowTitle:").SubItems.Add(p.MainWindowTitle);
        }
        catch (Win32Exception err)
        {
            lsvitems.Items.Add("MainWindowTitle:").SubItems.Add(err.Message);
        }
        try
        {
            lsvitems.Items.Add("MaxWorkingSet:").SubItems.Add(p.MaxWorkingSet.ToString());
        }
        catch (Win32Exception err)
        {
            lsvitems.Items.Add("MaxWorkingSet:").SubItems.Add(err.Message);
        }
        try
        {
            lsvitems.Items.Add("MinWorkingSet:").SubItems.Add(p.MinWorkingSet.ToString());
        }
        catch (Win32Exception err)
        {
            lsvitems.Items.Add("MinWorkingSet:").SubItems.Add(err.Message);
        }
        try
        {
            lsvitems.Items.Add("PagedMemorySize64:").SubItems.Add(p.PagedMemorySize64.ToString());
        }
        catch (Win32Exception err)
        {
            lsvitems.Items.Add("PagedMemorySize64:").SubItems.Add(err.Message);
        }
        try
        {
            lsvitems.Items.Add("PagedSystemMemorySize64:").SubItems.Add(p.PagedSystemMemorySize64.ToString());
        }
        catch (Win32Exception err)
        {
            lsvitems.Items.Add("PagedSystemMemorySize64:").SubItems.Add(err.Message);
        }
        try
        {
            lsvitems.Items.Add("PeakPagedMemorySize64:").SubItems.Add(p.PeakPagedMemorySize64.ToString());
        }
        catch (Win32Exception err)
        {
            lsvitems.Items.Add("PeakPagedMemorySize64:").SubItems.Add(err.Message);
        }
        try
        {
            lsvitems.Items.Add("PeakWorkingSet64:").SubItems.Add(p.PeakWorkingSet64.ToString());
        }
        catch (Win32Exception err)
        {
            lsvitems.Items.Add("PeakWorkingSet64:").SubItems.Add(err.Message);
        }
        try
        {
            lsvitems.Items.Add("PriorityClass:").SubItems.Add(p.PriorityClass.ToString());
        }
        catch (Win32Exception err)
        {
            lsvitems.Items.Add("PriorityClass:").SubItems.Add(err.Message);
        }
        try
        {
            lsvitems.Items.Add("FileName:").SubItems.Add(p.StartInfo.FileName);
        }
        catch (Win32Exception err)
        {
            lsvitems.Items.Add("FileName:").SubItems.Add(err.Message);
        }
        try
        {
            lsvitems.Items.Add("StartTime:").SubItems.Add(p.StartTime.ToShortTimeString() + " " + p.StartTime.ToShortDateString());
        }
        catch (Win32Exception err)
        {
            lsvitems.Items.Add("StartTime:").SubItems.Add(err.Message);
        }
        try
        {
            lsvitems.Items.Add("UserProcessorTime:").SubItems.Add(p.UserProcessorTime.TotalSeconds.ToString() + " Sec");
        }
        catch (Win32Exception err)
        {
            lsvitems.Items.Add("UserProcessorTime:").SubItems.Add(err.Message);
        }
        try
        {
            lsvitems.Items.Add("PrivilegedProcessorTime:").SubItems.Add(p.PrivilegedProcessorTime.TotalSeconds.ToString() + " Sec");
        }
        catch (Win32Exception err)
        {
            lsvitems.Items.Add("PrivilegedProcessorTime:").SubItems.Add(err.Message);
        }
        try
        {
            lsvitems.Items.Add("TotalProcessorTime:").SubItems.Add(p.TotalProcessorTime.TotalSeconds.ToString() + " Sec");
        }
        catch (Win32Exception err)
        {
            lsvitems.Items.Add("TotalProcessorTime:").SubItems.Add(err.Message);
        }
        try
        {
            lsvitems.Items.Add("VirtualMemorySize64:").SubItems.Add(p.VirtualMemorySize64.ToString());
        }
        catch (Win32Exception err)
        {
            lsvitems.Items.Add("VirtualMemorySize64:").SubItems.Add(err.Message);
        }
        try
        {
            lsvitems.Items.Add("Company Name:").SubItems.Add(p.MainModule.FileVersionInfo.CompanyName);
        }
        catch (Win32Exception err)
        {
            lsvitems.Items.Add("Company Name:").SubItems.Add(err.Message);
        }
        try
        {
            lsvitems.Items.Add("FileVersion:").SubItems.Add(p.MainModule.FileVersionInfo.FileVersion);
        }
        catch (Win32Exception err)
        {
            lsvitems.Items.Add("FileVersion:").SubItems.Add(err.Message);
        }
        try
        {
            lsvitems.Items.Add("LegalCopyright:").SubItems.Add(p.MainModule.FileVersionInfo.LegalCopyright);
        }
        catch (Win32Exception err)
        {
            lsvitems.Items.Add("LegalCopyright:").SubItems.Add(err.Message);
        }
        try
        {
            lsvitems.Items.Add("FileDescription:").SubItems.Add(p.MainModule.FileVersionInfo.FileDescription);
        }
        catch (Win32Exception err)
        {
            lsvitems.Items.Add("FileDescription:").SubItems.Add(err.Message);
        }
        try
        {
            lsvitems.Items.Add("Language:").SubItems.Add(p.MainModule.FileVersionInfo.Language);
        }
        catch (Win32Exception err)
        {
            lsvitems.Items.Add("Language:").SubItems.Add(err.Message);
        }
    }

    private void Get_modules(ProcessModuleCollection prcmdlclc)
    {
        ListViewItem lstviewitm = new ListViewItem();
        lsvmodules.Items.Clear();
        foreach (ProcessModule prcmdl in prcmdlclc)
        {
            try
            {
                lstviewitm = lsvmodules.Items.Add(prcmdl.ModuleName);
                lstviewitm.SubItems.Add(prcmdl.FileVersionInfo.FileName);
                lstviewitm.SubItems.Add(prcmdl.FileVersionInfo.ProductName);
                lstviewitm.SubItems.Add(prcmdl.FileVersionInfo.ProductVersion);
            }
            catch (ArgumentException err)
            {
                MessageBox.Show(err.Message, this.Text, MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
    }

    private void lsvproccess_SelectedIndexChanged(object sender, EventArgs e)
    {
        Int32 pid;
        lsvitems.Items.Clear();
        ListView lsvview = new ListView();
        if (lsvproccess.FocusedItem != null)
        {
            int index = lsvproccess.FocusedItem.Index;
            Process p = new Process();
            pid = Convert.ToInt32(lsvproccess.Items[index].SubItems[2].Text);
            p = Process.GetProcessById(pid);
            Detail_process(p);    // detailing each process in right side listview
            try
            {
                if (chbxmodule.Checked)
                    Get_modules(p.Modules);
            }
            catch (Win32Exception err)
            {
                MessageBox.Show(err.Message, this.Text, MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
    }
</code>
Answer: Run your exe as Administrator. Syste
m task manager have same problems. It is because until you aren't an administrator you cannot view process details.
Comment: Try to debug your function. You do not provide so it is difficult to find an answer.

process listing and it details


db_select with groupBy(CAST(column as DATE))

Question: I am looking to achieve GROUP BY CAST(date_time AS DATE) in a db_select function in Drupal 7 but with no idea how.
The function up until now is:
 foreach ($distinct_users as $user){
    $day_record = db_select('mytable', 'p')
      ->condition('p.processed', 0, '=')
      ->condition('p.first_name', $user['first_name'], '=')
      ->condition('p.last_name', $user['last_name'], '=')

and I need to group the results by day which is in Y-m-d H:i:s in my table column.
Please advise.
Comment: Try with `$connection = Database::getConnection();
$sth = $connection->select('mytable', 'p');
$sth->condition('p.processed', 0, '=')
  ->condition('p.first_name', $user['first_name'], '=')
  ->condition('p.last_name', $user['last_name'], '=');

$sth->addExpression('CAST(p.date_time)', 'cast');
$sth->groupBy('p.date_time');
// Execute the statement
$data = $sth->execute();
// Get all the results
$results = $data->fetchAll(\PDO::FETCH_ASSOC);` see here https://www.drupal.org/forum/support/module-development-and-code-questions/2015-03-27/count-with-group-by-clause-in-db
Comment: Well, pretty close to be honest.
Now I get an array. Seems to return the right number of elements but it only returns the casted date.

Something like $results{array}
0 = {StdClass}[1]
cast = "2019-11-01"

And so on.
Comment: Can you update your question with some examples of the rows in the database table, and what the array returned by a db_select() function on those rows should look like? If you know the SQL statement that gives the results you are looking for, then including that may be helpful as well.
Comment: I found a workaround, I am currently grouping them in PHP instead of getting them grouped from SQL.
What I was looking for was to get this into Drupal 7.
SELECT * FROM mytable AS p WHERE p.processed = 0 AND p.first_name = my users's first name AND p.last_name = my user's last name GROUP BY CAST(p.date_time AS DATE).
Answer: The solution that worked for me was to group results via php.


Relacionamento SQL

Question: Boa noite, estou criando um pequeno sistema no qual terei um formulário para Atendimento, onde o usuário irá selecionar um Cliente, e haverá um checkbox para multipla escolha para Serviços.
Alguém pode me dizer se minha linha de pensamento está correta?
Tabelas:
*Cliente
idCliente
nomeCliente
...
*Servico
idServico
descricao
valorServico
*Atendimento
idAtendimento
dataAtendimento
valorTotal
idServico - N - servicos
idCliente - 1 - cliente

Atendimento_Servico
idAtendimento_Servico
idAtendimento
idServico

Caso de uso:
Cadastrando um atendimento com um cliente e 3 servicos selecionados via checkbox:
atendimento    cliente          servico
1                            1        1,2,3
atendimento   atendimento_servico     servico
1                            1,1                            11                            1,2                             21                            1,3                            3
Answer: Precisa ter uma tabela relacional entre atendimento e serviço, já que o relacionamento entre atendimento e serviço é n-para-n.
Basicamente, ficaria algo assim:
Comment: E a tabela 'atendimento_has_servico'  não precisa ter um id próprio?
Comment: Há quem queira criar um ID, há quem não queira. Você pode querer criar uma chave composta que é a junção do `atendimento_id` e do `servico_id`, assim nunca haverá duplicatas.

Relacionamento SQL


Microsoft Exchange for Mac

Question: So I need to setup 4 macs and 4 iphones with a Mac Mini with Leopard Server that will do contact and calendar syncing with all the devices, inside or outside the network. Apparently OS X Server doesn't do that (refering to syntaxcollector's answer to my previous question: Mac OS X Server: Snow or not?)
He recommended me Kerio MailServer to do contact and calendar syncing. 599$. What am I not getting here? What is the purpose of Leopard Server if it doesn't do this? What do you use to do contact/calendar syncing?
Comment: Can you clarify "What is the purpose of Leopard Server if it doesn't do this" please? Do you mean "why do I need Kerio AND 10.5 Server instead of Kerio installed on 10.5 Client" or do you mean "what other features does 10.5 Server have besides calendering" or? Fwiw, Snow Leopard server has a new AddressBook server and its iCal service works better now with clients that aren't bound
Comment: I meant "why do I need Kerio AND 10.5 Server instead of Kerio installed on 10.5 Client". Would love to have an answer to that question.
Answer: Be careful with your terminology:
Leopard Server (10.5) does not support Contact Sync (Address Book Server), neither do Leopard Clients (10.5).
Only Snow Leopard Clients (10.6) and Snow Leopard Server (10.6) support Contact Sync out-of-the-box.
Comment: @Sam V: Calendar syncing works with 10.5, I'm afraid I don't have any recommendations for contact sync. I don't know your reasons for not wanting to upgrade clients, but bear in mind Snow Leopard (10.6) Server unlimited client licence (more than 10 users) is only $499, and $29 per client. Can really not upgrade to Snow Leopard?
Comment: Thanks for clarification. So if I don't want to upgrade the clients to 10.6, but want to have contact/calendar syncing, what do you recommend I should use? Thanks.
Comment: I'm having a bad personal experience with SL client. Never regretted so much of doing an OS upgrade in 10 years of using Macs.
Answer: You could probably use this for calendar syncing:
http://trac.calendarserver.org/
If you don't want to pay a lot and not host it, gmail does a great job for syncing everything (calendar, contacts ect).
Comment: Google Calendar works fine, however contact syncing is extremely frustrating especially with Address Book. In my experience, contacts sync fine between server and iPhone, but not with Address Book.

Microsoft Exchange for Mac


How to create titled Imgur Albums via the API?

Question: I can create albums, using the requests and oauth-hook modules just fine, but I can't seem to get a name working. Check out the docs here: http://api.imgur.com/resources_auth#account_albums . I'm using Windows7x64 Python2.7, requests version 0.21.1 and oauth-hook version 0.4.0
Strangely, using the same approach to name an image when I upload it, the script works just fine. Here's the relevant code:
client = requests.session(hooks={'pre_request': authorizedHook})

url = r'http://api.imgur.com/2/account/albums.json'

parameters = {'title': 'ALBUMTITLEHERE'}

r = client.post(url, data=parameters)

which returns something like this, once I load it into json:
    Created Album data:
    {u'albums': {u'anonymous_link': u'http://imgur.com/a/i3Gal',
                 u'cover': u'',
                 u'datetime': u'2012-05-24 02:34:42',
                 u'description': u'',
                 u'id': u'i3Gal',
                 u'layout': u'blog',
                 u'link': u'http://tankorsmash.imgur.com/1B498',
                 u'order': 0,
                 u'privacy': u'public',
                 u'title': u''}}

What I was expecting was a named gallery called ALBUMTITLEHERE. But created an untitled one instead. What am I doing wrong?
Unrelated: The Stats API doesn't seem to be returning anything at all for me, but I'm not sure that's relevant.
Comment: Does requests have a debug mode? I would guess it would be clear if you had a look at the data that was actually being sent over by your request. There is sample code at the documentation link you included.
Comment: @valdarin A week later, I can see that my comment didn't get posted. I didn't find anything that stuck out to me.
Answer: Edit:
I've tried it myself now for quite some time, tried nearly every possible combination of parameters sent as http url parameter, post (json, urlencoded, even xml)... even analyzed raw requests in wireshark - everything works as it should.
But no luck, it doesn't work.
I'm quite sure this is a bug in the API itself. It's also impossible to change the title of an existing album.
So my previous response doesn't apply.
Comment: Can you confirm it works on your end? I am getting `This method requires authentication` errors when I change the `Content-type` to `application/json`, and transform the params the json. Removing that header and using the old param dict still works as usual.
Comment: As long as the OAuth hook has `header_oauth = True` I don't get  that authentication error. But then the returned album is still untitled, even with the json params and header.

Though the `stats` api works but that could be on their end, since the browser page isn't blank any more either..
Comment: Alright, thanks for the help, here's the bounty, since you put in a good deal of time into this. Thanks again.


How to smooth out a distribution towards a specific number

Question: I am working on a video game where the enemy units need to be dispatched onto the screen at a regular interval, but must remain somewhat random.  So lets say I need to put them onto the screen at a rate of 30 per minute.
Currently I randomly pick an integer between [1 - 100] every 600 ms.  If the number is 30 or less, then a unit is dispatched.  If the number is greater than 30, I do not dispatch the unit.  Because there are 100 600 ms intervals within 60 seconds I do arrive at the goal of 30 units per minute.
The problem is that the distribution is not that even.  Sometime there are periods of not many units being dispatched, and other times when there are too many.
Is there a way I can smooth out the distribution so that it remains randomish but allows for a more consistent flow of units?
EDIT:  I followed @Ross Millikan 's advice and below are the results.  Definitely a lot smoother using his algorithm.
3 units randomly distributed every 10 slots
___X___X_X___XXX_____X_____X_X______XX_X_X_____XX_X_X______X__X__XX____X____X__X_____XX_X____X_XX___X___X___X___X___X__X___X_X___X_____XX_X_X__XX______XXX_________X__X__X_____XX_X______X_XX___X_X___X_X___X_X____X_____XX__X_X_X________XXX_____X____X_X_X_X___X___X_X___X__X_X____X____XX_X_____XX_____X____X___XX______XX_X_X____X___X____X_X_X____X__X__X__X____XX__XX___X_______X__X_XX______X_X____X__X_X_X_X_X_____X___X__X____X___XX___X____X_XX_X___X___X_X______XX__X_X_____X______XX_X__X_X_________XX_X____X_X_X_XX___X_____X_X__X___X_____X__X_X_____XX_X_X_X_____X____X___XX__X_X_____X___X_X__X_X_X________XX___X_____X__XX__X__X__X____X__X___XX_______XXX_______XXX_X__X________X___XXX____XX_______X_X__X__XX____X__X__X____X_____XX_X_____X_XX___X__X___X___X_X_X____X__X____X__X__X__X_X___XX______X___XX______X_XX____XX_____X_X____XX__X_X____X__XX___X_____X___X__X___X__X_X__X___XX____X___X_X_____X____XX_X______X_XX__X_____X_X______XX___X_X___XX_____XX__X__X_____X___X_X__X___X_XX____X_____XX__XXX_______
30 out of 100 chance of a unit at every slot
X__XX___X__XXX___XX_XX__X_______X_XX_____X_XX_X_______X__X_XX_____________X___X___X______X_X__XX____X____X___XX_X_XX___XX______X________X__X______X_________________X___X____X__________XX__X________XX__X_______X_XX_X__XX_X_X_XXX__________X____X____________X__X______XX__XXXXXX_X_____X______X___XXX__X_XX__XX_X__X____X___XXX__X_X__XX____XX____X___XX_______X______X__X_XX_____XX_X__XX_XXX__XXX_____XX___XXXXX___X_XXX_____X_X_____X__X__XX_________XXX_______X___XX___XX_X____XX__XX___X___XX_____X_______X__________X_________X_____________XX___XX__X_X_X___X_XXX_______XXXX_X_XX__X_X___X______XX_______XXX______X_X_X____X____X_X___X_XXX_XXX_X__X___XX___X____X_____X_X_X__X_____________X_X______X_XX_____XXX_____XXX___X________X____X_X___X_____X_X_X___XXXX________X____X__X__X__X___________X______XXX____X__X______X___XX_XX__________XXX_____X__X______XX_XX___X____XXXX______X___X______X____X__X___X__X______X_XX__X____X__XX_XX_____X____XX______X___X_X___X_X_____X__X__XX__XX_XX_X__XXX_X_X___X___X___X___X_X__
Below is the java code.  Because I have to calculate this stuff in between frames in a video game, I stay away from decimal math.  So the whole implementation is done using int's.
<code>public static void main(String[] args) throws InterruptedException {
    nonUniformDispatch();
    uniformDispatch();
}

static void nonUniformDispatch() throws InterruptedException {
    Random rand = new Random();
    double it = 1_000;
    int goal = 30;
    int dispatches = 0;
    for (int i = 0; i < it; i++) {
        if (goal > rand.nextInt(100)) {
            dispatches++;
            System.out.print("X");
        } else {
            System.out.print("_");
        }
    }
    System.out.println("\n\ndispatches = " + dispatches);
}

static void uniformDispatch() throws InterruptedException {
    int totalUnits = 3;
    Random rand = new Random();
    double it = 1_000;
    int dispatches = 0;
    int totalSlots = 10;
    int unitsRemaining = totalUnits;
    int slotsRemaining = totalSlots;
    StringBuilder sb = new StringBuilder();
    for (int i = 0; i < it; i++) {
//            System.out.println("slotsRemaining = " + slotsRemaining + ", unitsRemaining = " + unitsRemaining);
        if (slotsRemaining <= unitsRemaining) {
            dispatches++;
            unitsRemaining--;
            sb.append("X");
        } else if (unitsRemaining > 0) {
            int x = (unitsRemaining * 100) / slotsRemaining;
            if (x > rand.nextInt(100)) {
                dispatches++;
                unitsRemaining--;
                sb.append("X");
//                    System.out.println("x = " + x + ", hit");
            } else {
                sb.append("_");
//                    System.out.println("x = " + x + ", miss");
            }
        } else {
            sb.append("_");
//                System.out.println("miss");
        }
        slotsRemaining--;
        if (slotsRemaining == 0) {
            slotsRemaining = totalSlots;
            unitsRemaining = totalUnits;
        }
    }
    System.out.println(sb.toString());
    System.out.println("\n\ndispatches = " + dispatches);
    TimeUnit.SECONDS.sleep(10);
}
</code>
Answer: You could take longer time intervals.  If you take an interval of $6$ seconds you want an average of $3$ units per interval.  Now take a random number $1$ to $5$ for the actual number you will dispatch, then pick that many random times in the interval for the exact times you dispatch them.
Comment: Oh man this is good.  Let me try it out.
Answer: How about you plan to dispatch exactly one unit in every 2 second time interval using the random number generator to determine precisely when the unit is dispatched.
That way there will never be more than two units dispatched close to simultaneously and the time between dispatches will never be more than 4 seconds.


Combine two methods. int cannot be dereferenced

Question: If a woman has a partner, erase that partner's partner.
I need to retrieve her partner then make that partner single.
How do I combine getPartner() with erasePartner()
if (w.hasPartner() == true) {
    w.getPartner().erasePartner();
}

import java.util.*;

public class Person {
    public static final int NOBODY = -1;

    private String name;
    private List<Integer> preferences;
    private List<Integer> oldPreferences;
    private int partner;

    public Person(String name) {
        this.name = name;
        preferences = new ArrayList<Integer>();
        oldPreferences = new ArrayList<Integer>();
        erasePartner();
    }

    public void erasePartner() {
        partner = NOBODY;
    }

    public boolean hasPartner() {
        return partner != NOBODY;
    }

    public int getPartner() {
        return partner;
    }

    public void setPartner(int partner) {
        this.partner = partner;
    }

    public String getName() {
        return name;
    }

    public boolean hasChoices() {
        return !preferences.isEmpty();
    }

    public int getFirstChoice() {
        return preferences.get(0);
    }

    public void addChoice(int person) {
        preferences.add(person);
        oldPreferences.add(person);
    }

    public List<Integer> getChoices() {
        return preferences;
    }

    public int getPartnerRank() {
        return oldPreferences.indexOf(partner) + 1;
    }
}

Comment: You need to tag the language you are using.
Comment: Well.. What is `erasePartner`? Also you don't need `== true`. You can simply have `if(w.hasPartner())`
Comment: There is no need for `getPartner()` here.
Answer: Right now you have partner as an int. You cannot call methods on an int since it is a primitive type. However this doesn't make much sense in your context since you are erasing w's partner and not the partner's partner. Instead just call:
if (w.hasPartner() == true) {
    w.erasePartner();
}

Also your code doesn't make much sense. Why is the partner an int? Why wouldn't it be a Person object. You could change your code to:
private Person partner;

And
public Person getPartner() {
    return partner;
}

So that partner points to another Person object instead of an int
Comment: w.erasePartner(); will erase the woman's partner. I need to get her partner and erase that partner's partner.
Comment: the whole class person was provided for me and I can't edit it
Comment: @2cs `partner` is an `int` and does not have a `partner`
Comment: I have methods that set partners like w.setPartner(3); so now I want to retrieve that 3 and erase it which is -1
Comment: @2cs So at the end you want `w.getPartner() == -1`?
Answer: You need to be able to get the Persona that the partner field corresponds to if you want to erase the partner's partner.
Given the code that you have, every Person should have a corresponding id that is an int, which is the value the partner field stores. You'll need some way to store these mappings such as a Map<Integer, Persona> that lives outside the Person class, and whenever you create a Person you have to put it in the map along with its id (which you can generate however you like as long as it's unique).
With this map you can then access the Person that corresponds to the partner int and erase its partner
if (w.hasParter()) {
  Person partner = personMap.get(w.getPartner());
  partner.erasePartner()
}

assuming the partner exists in the map (which you may want to check for).
Answer: Okay I kinda figured it out. I did it another way. Goes through each person and test's to see if person p is partner with firstChoice then deletes the p's partner. Kinda long way it seems but it works :)
for (Person p : list1) {
    if (p.getPartner() == firstChoice) {
    p.erasePartner();
                }


excessive ram usage by pop3-login and imap-login

Question: I have a VPS with DirectAdmin and Dovecot installed on it. On this server on one of my accounts I have 3 different main account which I've managed using gmail and it's pop3 import feature.
The problem is that the ram usage has gone up from around 300MB to something like 800MB. Through ssh and the 'top' command I can see that there are multiple 'imap-login' and 'pop3-login' instances running on the machine and eating a hell of a lot of memory.
Is there any way to reduce the memory usage by these application?
Comment: [Administration panels are off topic](http://serverfault.com/help/on-topic). [Even the presence of an administration panel on a system,](http://meta.serverfault.com/q/6538/118258) because they [take over the systems in strange and non-standard ways, making it difficult or even impossible for actual system administrators to manage the servers normally](http://meta.serverfault.com/a/3924/118258), and tend to indicate low-quality questions from *users* with insufficient knowledge for this site.
Answer: What version of Dovecot are you running?
Make sure you're running the latest version which you can install using Directadmin's Custombuild.
Also, you might want to check <code>/var/log/maillog</code>, which is where Dovecot usually write its logs, to see if there's anything strange.


About slash and 7th chord's meaning and their history

Question: In today's music, there are certain musical features that makes music jazzy and good and I think those are the use of 7th chords and tensions. And of course there are Slash chords(along with them, if sus4 chords when containing 9,4,7 are considered a slash chord too. This sounds so awesome.)
Slash chords has some kind of effect that makes them as equally good as 7th or chords with tension. Could you explain as to what makes it so?
I once try to find 7chords but in Mozart of Beethhoven, they only use diminished and dominant 7th chords, it seems, except on the sonata piece where Mozart daringly uses m7-7-M7-M7-m7-7 in his KV332 sonata. But they from time to time uses those slash chords that has a strong effect. I read once that jazz musicians invented slash chords but that must mean something different to the chords used in past music?
And vaguely when music stared to use 7 chords purely for thier effect? I can only name Gymnopedie so far.
So, the questions are...
Q1. What makes slash chords equally sound good as 7th and the ones with tensions in contemporary musics? I'm thinking of contemporary music as those of jazzy ones, r&b, funk and maybe in Steely Dan. I'm sorry I can't name specifically what chords since there are many but if you want I'll get an examples of them.
Q2. I've read that Jazz musicians kind of invented or modified slash chords to their tastes. To what extent are these chords modified? Simply by adding 7th and using tension notes?
Q3. Since when 7th chords was recognised of its value in music history? It seems to me that 18th century's music was very careful in using them but didn't fail to know what these chords can do. Was it so dissonant and unfamiliar in their ears?
Comment: Thomas Tallis's _Spem in alium_ has a major seventh chord in it; it was written around 1570.
Answer: 7th, 9th, 11th, and 13th chords were certainly not "invented" by jazz musicians. They are all described in the standard 19th-century harmony textbooks - for example Prout https://imslp.org/wiki/Special:ImagefromIndex/240170/torat (Chapter 13 onwards), MacPherson https://archive.org/details/melodyharmonytre00macpuoft (Part III), etc.
Many of them were decribed even earlier, for example in CPE Bach's "Essay on the true art of of playing keyboard instruments" first published in 1753, but since that book was not influenced by Rameau's publication (1744) of his theoretical discovery of chord inversions, and doesn't make use of the principle that "chords" can be constructed by stacking intervals of a third, it isn't a simple task to re-order CPE Bach's discussion of these chords into the same logical sequence (and the same naming conventions) as a modern harmony textbook.
"Slash chords" have been used for at least 1,000 years in western music, at least over long sustained bass notes. Even "polychords" (e.g. a G7 chord over a C major chord) occur in Beethoven, e.g. the piano sonata Op 81a "Les Adieux", near the end of the first movement.
Whether jazz musicians rediscovered them independently is a different question, of course (and not one that I can answer).
In fact, the Baroque period was generally more "adventurous" with 7th chords of all types than the early Classical composers. J S Bach certainly used them for "effect" - for example the string of diminished 7ths towards the end of BWV715:

.
(There are better performances of this on YouTube, but this one shows the score).
Answer: A "slash chord" is not a chord type but a short-hand notation.
It can be a simplified description of the chord, emphasizing what's played in the bass note:
C/E       is just C
G/F       is G7
F/G       is just G7sus
Caug/D    is just D7 11+

Or it can encode notable bass patterns, like pedal note or walking bass, like C C/Bb C C/Bb or Cm Cm/B Cm/Bb Cm/A.
So, of course, there's no separate "slash chord" sound. It's purely a notational utility.
Comment: "not a chord type": there are all sorts of nitpicky ways in which you could argue that it is a chord type, at least including "the type of chord where the bass is playing something other than the root."  I mean, your point is well taken, so +1, but I have a feeling there's a better way to put the first sentence.  Unfortunately I can't think of it just now.
Comment: @phoog sorry if it came out rude or anything, but really, slash chord is literally describes the notation ("written with a slash"), not the quality. Is CM7 a slash chord? No, it's a major seventh chord. But you can notate is as Em/C - and then it is. Is Am7 a slash chord? No, but it can be notated as C/A. And then it becomes one, but just in the notation, the sound remains the same.


Estimate optimal cutoff for time-dependent ROC

Question: Recently I am working with survival data and trying to fit time-dependent ROC.
And I have difficulty estimating the optimal cutoff for time-dependent ROC.
Here is the process I do.
library(survival)
library(timeROC)
library(survivalROC)

data(pbc)
head(pbc)
pbc<-pbc[!is.na(pbc$trt),]
pbc$status<-as.numeric(pbc$status==2) # create event indicator: 1 for death, 0 for censored

ROC.bili1<-timeROC(T=pbc$time,
                  delta=pbc$status,marker=pbc$bili,
                  cause=1,weighting="marginal",
                  times=c(365,365*3,365*5,365*10),
                  iid=TRUE)
ROC.bili1

And here are the results
Time-dependent-Roc curve estimated using IPCW  (n=312, without competing risks).
       Cases Survivors Censored AUC (%)   se
t=365     22       290        0   85.59 3.51
t=1095    59       240       13   85.02 2.68
t=1825    85       159       68   87.58 2.29
t=3650   120        32      160   81.57 3.85

Method used for estimating IPCW:marginal

Total computation time : 0.29  secs.

Next step, I would like to estimate the optimal cutoff in 10 years (time = 365*10)
However, it seems that timeROC does not return the results I want.
And it is reported that survivalROC does.
ROC.bili2<-survivalROC(Stime=pbc$time,
                       status=pbc$status,
                       marker=pbc$bili,
                       predict.time=365*10,
                       method = 'KM')

Estimate the optimal cutoff
ROC.bili2$cut.values[which.max(ROC.bili2$TP-ROC.bili2$FP)]
[1] 1.9

And calculate the AUC
ROC.bili2[["AUC"]]
[1] 0.8394563

I got the optimal cutoff is 1.9, but the AUC is 0.8394 which is different from using timeROC (0.8157)
So my question is

If I can use 1.9 as the optimal cutoff?

Why is the AUC difference between  timeROC and survivalROC

Is there any way to calculate the optimal cutoff using timeROC

Any insight is appreciated.
Answer: Defining time-dependent receiver operating characteristic (ROC) curves for censored survival data is not a trivial problem. For an introduction to the issues, I'd suggest reading "Survival Model Predictive Accuracy and ROC Curves" by Heagerty and Zheng, Biometrics 61: 92–105 (2005). That describes a more recent approach, implemented in the risksetROC package, than that of Heagerty et al. implemented in the survivalROC package.
Those approaches differ from the inverse probability of censoring weighting method used in the timeROC package. So it's not surprising that you get slightly different AUC estimates for the two methods that you tried.
Your approach to determining an "optimal cutoff" might be highly flawed. Any "optimal" point on an ROC curve depends on the relative costs and benefits of different types of true and false predictions. Unless you take those costs into account you don't have an "optimal" cutoff. And even if an "optimal" cutoff on that basis could be available, you might want to use further information to guide practical decisions.
You chose to use the point on the curve with the highest difference between true-positive and false-positive predictions as "optimal," but that only would make sense if (1) you can completely ignore the costs/benefits of true-negative and false-negative results and (2) the cost of 1 false-positive result exactly balances the gain from 1 true-positive result. It's hard to think of a practical situation where those conditions would hold.
Software-specific questions are off-topic on this site devoted to statistics. Presumably, timeROC() provides the details of its ROC curves (sensitivity/specificity as a function of biomarker value) somewhere in the object it returns. If you have a valid criterion for an "optimal" cutoff, you should be able to apply that criterion to the ROC with a bit of manipulation.
Comment: Thank you for your detailed answers. As for the method I used to select the optimal cutoffs, the maximum Youden index was used, As the Youden index = Sen + Spec -1, it also can be calculated by TP - FP (TP = Sen and FP = 1 - Spec). I hope it's right.   Actually, I can calculate the maximum (TP-FP) in `timeROC`, but it didn't provide the value (bili in this case) accordingly.
Comment: @Lyn the problem with the [Youden Index](https://en.wikipedia.org/wiki/Youden's_J_statistic) is that "[t]he index gives equal weight to false positive and false negative values." That's not how you would typically evaluate a clinical test, for example. The matrices of TP and FP rates returned by the`timeROC()` function are based on the set of `marker` values and `times` that you specified in the call to the function, so the `bili`value would be the value in your `marker` set that corresponds to the position of the maximum (TP-FP) at the time in question, if you want to use the Youden index.


PHP Verificar dispositivo mobile

Question: Eu preciso via PHP, de alguma função que me indique se o dispositivo do usuário é mobile ou não, ou, que pelo menos me diga a resolução do mesmo. Alguém tem alguma dica?
Comment: Se deseja pegar a resolução da tela pense em usar JavaScript, eu pessoalmente não conheço nenhuma solução de PHP para isso. Mas se quer realmente detectar aparelhos mobiles deixei um solução abaixo.
Answer: No site Detect Mobile Browsers conseguimos scripts capazes de detectar aplicativos mobiles, e em diferentes linguagens.
O código em PHP é esse:
<?php
 $useragent=$_SERVER['HTTP_USER_AGENT'];

 if(preg_match('/(android|bb\d+|meego).+mobile|avantgo|bada\/|blackberry|blazer|compal|elaine|fennec|hiptop|iemobile|ip(hone|od)|iris|kindle|lge |maemo|midp|mmp|mobile.+firefox|netfront|opera m(ob|in)i|palm( os)?|phone|p(ixi|re)\/|plucker|pocket|psp|series(4|6)0|symbian|treo|up\.(browser|link)|vodafone|wap|windows ce|xda|xiino/i',$useragent)||preg_match('/1207|6310|6590|3gso|4thp|50[1-6]i|770s|802s|a wa|abac|ac(er|oo|s\-)|ai(ko|rn)|al(av|ca|co)|amoi|an(ex|ny|yw)|aptu|ar(ch|go)|as(te|us)|attw|au(di|\-m|r |s )|avan|be(ck|ll|nq)|bi(lb|rd)|bl(ac|az)|br(e|v)w|bumb|bw\-(n|u)|c55\/|capi|ccwa|cdm\-|cell|chtm|cldc|cmd\-|co(mp|nd)|craw|da(it|ll|ng)|dbte|dc\-s|devi|dica|dmob|do(c|p)o|ds(12|\-d)|el(49|ai)|em(l2|ul)|er(ic|k0)|esl8|ez([4-7]0|os|wa|ze)|fetc|fly(\-|_)|g1 u|g560|gene|gf\-5|g\-mo|go(\.w|od)|gr(ad|un)|haie|hcit|hd\-(m|p|t)|hei\-|hi(pt|ta)|hp( i|ip)|hs\-c|ht(c(\-| |_|a|g|p|s|t)|tp)|hu(aw|tc)|i\-(20|go|ma)|i230|iac( |\-|\/)|ibro|idea|ig01|ikom|im1k|inno|ipaq|iris|ja(t|v)a|jbro|jemu|jigs|kddi|keji|kgt( |\/)|klon|kpt |kwc\-|kyo(c|k)|le(no|xi)|lg( g|\/(k|l|u)|50|54|\-[a-w])|libw|lynx|m1\-w|m3ga|m50\/|ma(te|ui|xo)|mc(01|21|ca)|m\-cr|me(rc|ri)|mi(o8|oa|ts)|mmef|mo(01|02|bi|de|do|t(\-| |o|v)|zz)|mt(50|p1|v )|mwbp|mywa|n10[0-2]|n20[2-3]|n30(0|2)|n50(0|2|5)|n7(0(0|1)|10)|ne((c|m)\-|on|tf|wf|wg|wt)|nok(6|i)|nzph|o2im|op(ti|wv)|oran|owg1|p800|pan(a|d|t)|pdxg|pg(13|\-([1-8]|c))|phil|pire|pl(ay|uc)|pn\-2|po(ck|rt|se)|prox|psio|pt\-g|qa\-a|qc(07|12|21|32|60|\-[2-7]|i\-)|qtek|r380|r600|raks|rim9|ro(ve|zo)|s55\/|sa(ge|ma|mm|ms|ny|va)|sc(01|h\-|oo|p\-)|sdk\/|se(c(\-|0|1)|47|mc|nd|ri)|sgh\-|shar|sie(\-|m)|sk\-0|sl(45|id)|sm(al|ar|b3|it|t5)|so(ft|ny)|sp(01|h\-|v\-|v )|sy(01|mb)|t2(18|50)|t6(00|10|18)|ta(gt|lk)|tcl\-|tdg\-|tel(i|m)|tim\-|t\-mo|to(pl|sh)|ts(70|m\-|m3|m5)|tx\-9|up(\.b|g1|si)|utst|v400|v750|veri|vi(rg|te)|vk(40|5[0-3]|\-v)|vm40|voda|vulc|vx(52|53|60|61|70|80|81|83|85|98)|w3c(\-| )|webc|whit|wi(g |nc|nw)|wmlb|wonu|x700|yas\-|your|zeto|zte\-/i',substr($useragent,0,4)))
   header('Location: http://detectmobilebrowser.com/mobile');

O código acima simplesmente testa se o user agent é mobile e redireciona a  chamada http.
Answer: Bem conforme os colegas já postagem em geral se compara o USER-AGENT ou seja o próprio navegador para determinar se é mobile ou não, o problema ao meu ver é que existe muitos modelos de aparelhos e navegadores então as vezes vários podem passar batido, então o ideial seria usar o USER-AGENT combinado com espressões regulares para garantir, mas isso também é chato e demorado, então eu tenho usado a classe Mobile Detect, que para mim tem sido bastante útil por que ela diz se é Tablet ou Telefone e qual o modelo exato também.
<?php
// Inclui e inicia a classe
require_once("Mobile_Detect.php");
$detect = new Mobile_Detect;

// Testa se é Tablet ou Telefone
if ($detect->isMobile()) {
 echo "Diz que é um Dispositivo Movel";
}

// Função que testa e diz a versão do aparelho
echo $detect->version("iPhone"); // 3.1 (float)
?>

Quanto a detectar a resolução você só vai conseguir usando JavaScript já que PHP só roda do lado do sevidor ou seja ele não tem acesso ao Hardware da máquina em sí.
Para isso você pode usar 2 tipos de funções básicas que combinadas viram 4, pois é sempre altura x largura que são elas:

screen.width: Pega a largura da tela da pessoa ou seja a resolução que a máquina está operando 800[x600] ou 1024[x768] ou 1920[x1080].
screen.height: Pega a altura da tela da pessoa ou seja a resolução que a maquina esta operando [800x]600 ou [1024x]768 ou [1920x]1080.
screen.availWidth: Pega a largura da tela da pessoa porém ela desconta as parte não usadas por você, como a barra de endereço do navegador a barra de rolagem, barra de favoritos entre outras que o usuário possa ter, ou seja ela é a área realmente utilizável do navegador e em geral sempre será menor que a área do "screen.width".
screen.availHeight: Pega a altura da tela da pessoa porém ela desconta as parte não usadas como a barra de endereço do navegador a barra de rolagem, barra de favoritos entre outras ou seja ela é a área realmente utilizável do navegador e em geral sempre será menor que a área do "screen.height".

Mas atenção: tanto screen.availWidth como a screen.availHeight não funcionam tão bem quanto deveriam e às vezes elas trazem valores estranhos.

Vale lembrar que existe outras formas de se capturar o tamanho da tela ou do documento HTML ou dos elementos, assim como a psoição do aparelho deitado (landscape) ou e pé (portrait), vou deixar esse link - First, Understand Your Screen - caso queira conhecer essas outras formas.
Answer: <?php
$iphone = strpos($_SERVER['HTTP_USER_AGENT'],"iPhone");
$ipad = strpos($_SERVER['HTTP_USER_AGENT'],"iPad");
$android = strpos($_SERVER['HTTP_USER_AGENT'],"Android");
$palmpre = strpos($_SERVER['HTTP_USER_AGENT'],"webOS");
$berry = strpos($_SERVER['HTTP_USER_AGENT'],"BlackBerry");
$ipod = strpos($_SERVER['HTTP_USER_AGENT'],"iPod");
$symbian =  strpos($_SERVER['HTTP_USER_AGENT'],"Symbian");

if ($iphone || $ipad || $android || $palmpre || $ipod || $berry || $symbian == true) {
    echo "Olá, eu sou mobile";
} else {
    echo "Olá, eu sou um computador";
}
?>

Comment: as 7 primeiras linhas pega vários sistemas, o if verifica qual é o mobile, por exemplo, se for android, ele vai considerar verdadeiro e vai mostrar a msg "Olá, eu sou mobile", e assim vai com os outros sistemas. e o else caso vc acesse pelo computador ele mostra a msg "Olá, eu sou um computador"
Answer: O melhor que eu achei espero ter ajudado!
<?php
$mobile = FALSE;

$user_agents = array("iPhone","iPad","Android","webOS","BlackBerry","iPod","Symbian","IsGeneric");

foreach($user_agents as $user_agent){

    if (strpos($_SERVER['HTTP_USER_AGENT'], $user_agent) !== FALSE) {
        $mobile = TRUE;

        $modelo = $user_agent;

        break;
    }
}

if ($mobile){

    echo "Acesso feito via ".strtolower($modelo);

}else{

    echo "Acesso feito via computador";
}
?>

Comment: Fiz uma edição para mostrar o código que você tinha colocado. Quando postar código em perguntas ou respostas, utilize o botão amostra de código (`{ }`) no editor.

PHP Verificar dispositivo mobile


Help with easy proof

Question: My name is Dennis and I need help solving.

Show that if $n\in\mathbb Z$ is odd, then $n$ is of the form $4q+1$ or $4q+3$ for some $q\in\mathbb Z$.

Now I know this is true so can't use a proof by contradiction.
However I believe I can proof this by proving that $4q+1$ or $4q+3$ is not even thus it must be odd.
Below is my work it will not be the greatest for I have been away from math for some years.
Suppose to the contrary that $n$ is even.
consider $n$ to be even and we know an even integer is of the form $n=2k$
let $k=2q$ and we assume that $n=2(2q)+1$ or if rewritten $n=2k+1$
therefore $n=2k+1\neq n4q+1$ and $4q+1$ and $4q+3$ are odd.
Comment: You are proving that if $n$ is of that form then $n$ is odd. You're supposed to be proving that if $n$ is odd then it is of that form.
Comment: so I need to prove that all odd numbers of Z are in this form.
How would I do that, I would think that I would prove all even numbers or not of this form.
Comment: "Now I know this is true so can't use a proof by contradiction." A proof by contradiction doesn't usually prove false statements :).
Comment: O I seem to have misunderstood stood the use of that way of doing a proof.
Answer: Let $n$ be an arbitrary odd number; we want to show that $n$ has the form $4q+1$ or $4q+3$.
But what does an "odd number" mean? It means something of the form $2m+1$ (for a whole number $m$), so the assumption is really $$n=2m+1$$
Now, $m$ itself is either even or odd. If we can show that no matter whether $m$ even or od then $n$ has one of the required forms, we will be through. If $m$ is even then $m=2k$ for some $k$, so
$$n=2m+1=2(2k)+1=4k+1$$
Then $k$ works as the $q$ we were looking for, which completes this case of the proof.
On the other hand, if $m$ is odd, that means $m=2k+1$ for some $k$, and then
$$n=2m+1=2(2k+1)+1=4k+2+1=4k+3$$
Then again $k$ works as $q$, and the proof is finished.
Alternative proof. We can also show the required implication in "contrapositive" form:

If $n$ does not have one of the forms $4q+1$ or $4q+3$, then $n$ is even.

We can always divide $n$ by 4 and get an integral quotient and remainder instead of continuing into decimans. This allows us to express any $n$ as
$$n=4q+r$$
where $r$ is either zero or a positive number less than $4$, that is, one of the numbers 0, 1, 2, or 3. By assumption $r=1$ and $r=3$ cannot be the case, so we have either $n=4q+0$ or $n=4q+2$. In either case $n$ is the sum of two even numbers ($4q$ is always even, and 0 and 2 are also even), and that means that $n$ is even too.
Comment: And, if needed, we can prove that the sum of two even numbers is even...(+1)$$$$ ;)
Answer: We can either $n$ divide by $4$.
That is, write $n=4q+r$, where $r,q\in\mathbb N$ and $r<4$. We have four options:

$r=0$, then $n$ is divisible by $4$, which makes it even.
$r=1$, then $n$ is indeed of the form $4q+1$.
$r=2$, then $n=4q+2$ which is the sum of two even numbers ($4q$ is even).
$r=3$, then $n=4q+3$.

Since $n$ is odd we have that either $r=1$ or $r=3$, and we are done.
Answer: If the remainder x when dividing by 4 was 4 or greater, 4 could be subtracted from x and 1 added to q until a remainder <4 is obtained. The possibilites for n are then 4q, 4q+1,4q+2 and 4q+3. 4q=2(2q) and 4q+2=2(2q+1), therefore n is even if n is not of the form 4q+1 or 4q+3.
Comment: So I should be using the division algorithm? to prove that for when n is odd the "remainder is odd as well?"
Answer: You can use proof by contradiction. Namely, suppose for contradiction that $\rm\:n\:$ is odd and not of the form $\rm\:4\:k+1\:$ or $\rm\:4\:k+3\:.\:$ By the Division algorithm we may write $\rm\: n = 4\ q + r\ $ for $\rm\ 0 \le r \le 3\:.\:$ By hypothesis $\rm\: r \ne 1,3\:$ so $\rm\:r = 0\ or\ 2\:$ is even, so  $\rm\:n = 4\ q + r\:$ is even, contra hypothesis. $\ $ QED
More generally one can show that if $\rm\:m\:$ is even then $\rm\:m\ q+r\:$ is odd $\:$ iff $\rm\ r\:$ is odd, simply because even + r = odd iff r is odd. This implies that the sense of "parity" descends from integers to integers modulo $\rm\:m\:,\:$ i.e. they have well-defined parity since it depends only on the remainder $\rm\:r\:,\:$ not on the quotient $\rm\:q\:.\:$ Further, all the usual rules of parity arithmetic also descend to the ring of integers modulo $\rm\:m\:,\:$  for example: $\:$ odd + even = odd, $\:$ odd^2 = odd,$\:$  etc - just as for integers. In fact there are many rings which similarly have a sense of parity, e.g. the Gaussian integers $\:\mathbb Z[i]\:$ where $\: a +  b\ i\ $ is even iff both $\:a\:$ and $\:b\:$ have the same parity. See this post for further discussion. Many of these matters will become clearer if one studies abstract algebra, esp. the concept of quotient rings, which generalizes the "modular" construction of the ring of integers modulo $\rm\:m\:.$
Comment: This is a very good post and helps me see I am clearly missing some basic understanding. My ability to write proofs is very weak. I believe I better start working on this if I aim to do well in this abstract algebra class.

Help with easy proof


Is there a way to locate an element from the page source (not from the DOM)?

Question: I am using Selenium Webdriver,Junit and the Java language. I have to find an element from the source of the page.  driver.getPageSource() doesn't seem to return the desired value from the pagesource.
Comment: Is there any particular reason that you are unable to use a lookup by ID, class, CSS selector or XPath?
Comment: what do you mean by "not from the DOM"?
Comment: I have to compare two values. Once is given on the  GUI(or in the DOM) and the other is accessed via pagesource. On the GUI (or DOM) I can locate the  element from ID,class,css selector etc but these commands do not work for the element present in source HTML (page source).
Comment: ...yes they do. That's what they're for; locating objects in HTML.
Comment: If you are having issues not being able to locate certain elements, install firebug and then the addon firepath to it.  Inspect whatever element you are looking for and ensure that it is not in a frame. Unless the item you are looking for is inside of Flash, you should be able to find it by the selectors mentioned above.
Comment: DOM/GUI/Page source are always in sync when it comes to display. Atleast major browsers made sure this works. If a page wants to display a value 10 in it's source..u see the same value in DOM & in UI too
Comment: Hi All, If you think I can locate the value from the pagesource, can you please let mme know  the code/coomand that I can use. As
Comment: Hi All, If you think I can locate the value from the pagesource, can you please let mme know  the code/coomand that I can use.  As driver.pagesource.* does not locate an element from the page source. As mentioned earlier the value is not present in the DOM.(There is no such command as driver.pagesource.findelement(By.*).
Answer: On the page source you should use a Java xml parser.
See example here: http://www.javacodegeeks.com/2013/05/parsing-xml-using-dom-sax-and-stax-parser-in-java.html


Existe como "linkar" um conteúdo especifico de um repositório no outro?

Question: Eu tenho um programa que precisa de algumas DDLs, essas DDLs estão disponíveis em outro Git, também no GitHub. Sendo assim, seria possível a minha biblioteca linkar tal arquivo ao tal repositório?
Para ser mais especifico, existe uma DDL (github.com/c-smile/.../64/sciter.dll) e ela é usada na meu programa. Eu queria incluir ela aqui, junto com o main.go, ao invés de ter que fazer manualmente.
Teria como criar um sciter.dll apontado para o tal GitHub? Um sciter.dll que seria fictício, onde ao usar o go get -x ou git clone iria ir ao github.com/c-smile para obter este conteúdo.
Isso é possível, como faria isso?
Answer: Creio que há uma maneira de fazer o que você está pensando, que é linkar um módulo de outro projeto ao seu.

Navegue pelo terminar até o diretório do seu projeto e digite: git submodule add https://github.com/<user>/nomeModulo nomeModulo
Se a versão do seu git for antiga, digite agora esse comando: git submodule update --init --recursive

Pronto, você importou o submódulo ao seu projeto!
Answer: A boa prática para esse seu problema é usar um; gerenciador de pacotes ou package management.
Os gerenciadores de pacotes são mais conhecidos dos usuários gerais em sistemas GNU/Linux, por possibilitarem a instalação de programas ou aplicativos pelo console. Os mais conhecidos são: APT (Advanced Packaging Tool), RPM (RPM Package Manager), entre outros... No Windows temos o Chocolatey.
Já em desenvolvimento de software, quando trabalhamos com componentização, com o objetivo de distribuir pedaços da aplicação; deve existir a preocupação de como distribuir esse componente. Já que duplicar código não é uma alternativa, e não centralizar a distribuição do componente, pode levar ao desuso deste em grandes empresas. Para isso servem os gerenciadores de pacote!
Usados tanto para componentes do back-end como front-end temos opções específicas para cada linguagem ou plataforma. Segue relação de vários conhecidos:

Java: Maven, Gradle
.Net: Nuget
Go: veja relação aqui

Se os seus pacotes puderem ser públicos, deve existir um repositório para Go que você possa usar. Daí o seu processo de build deverá ter acesso a esse repositório para usar o pacote publicado. Se tiver que ser privado, você deverá ter na sua infra-estrutura essa gestão.
Você também pode procurar por gerenciadores de pacotes universai, que aceitam diversos feeds, de diversas linguagens. Dê uma olhada no Azure DevOps Packages.
Comment: Isso me parece aumentar mais a complexidade do que reduzi-la. A dll (so, dylib) é usada somente para a interface gráfica. Quando faz o `clone` (ou usa `go get`) poderá executar o `go generator` que irá passar o dll para uma variável qualquer, já que compilar estaticamente não funciona. Assim, a cada uso essa dll é descompactada pela aplicação e consumida. A razão de importa-lo para o GitHub é para facilitar a compilação, já que não terá que copiar as dlls manualmente, se for compilar. Para o uso geral, o resultado do `go build`, o `exe`, já é suficiente. Ou, entendi seu post errado.
Comment: Eu não entendi pedaços do seu texto, portanto não tive a compreenção total do seu processo.
A dll em questão, é de um projeto público? Externo ao seu/ou sua empresa?
O que você quer dizer com "descompactar a dll", já que não é possível descompactar um binário.
Se o go build é suficiente, em qual momento você usa essa outra compilação e para quê?
Comment: A dll é publica, não é produzida por mim. O `go build` é preciso somente se alguém quiser alterar o meu código, que é aberto. Acredito que é ideal facilitar a edição. A ddl é embutida dentro do meu programa. Quando usa o `go generate` adiconado um código cria o `sciter_windows.go` ele terá o `var DLL = {0x00.binario..}`. Quando você for usar o programa, a `dll` vai ser descompactada (tipo `os.Write(DLL)`) e então usada. Para o usuário final, que baixa já o `exe`, não há qualquer necessidade de ter a dll, porque ele já tem. O problema é quem quer compilar que acaba tendo que baixar manualmente.
Comment: Em resumo, a dll é necessária porque ela faz parte do código, literalmente. Então para alguém compilar (para criar o tal `var DLL = {conteudo do dll}`) terá que ter as dlls. Atualmente a pessoa deve ir no site da Sciter e baixa-la, então inclui-la na pasta e depois usar o `go generate`, isso me parece uma perde da tempo. Se eu incluir as dlls direto no meu GitHub terei que ficar atualizando, mas essa ainda parece ser a melhor saída, mas tem a questão das licenças.
Comment: É uma decisão sua... eu dei a melhor prática, que é o usado pelo mercado, e o por que não é uma perda de tempo.


Working with dataframe variable names passed as arguments to the R function

Question: I want to fit a statistical model (e.g. a linear one) for arbitrary variables from the dataframe passed as arguments to a function.
E.g.
myLm = function(x,y) {
    fit = lm(y~x, data=mtcars)}
myLm("cyl","mpg")

But this does not work.
How do I do that correctly?
Comment: What are "cyl" and "mpg" supposed to be? At the moment they are just strings.
Comment: you might want to try without the quotation marks, i.e. myLm(cyl, mpg)
Comment: You are passing string "cyl" not variable cyl.
Comment: "cyl" and "mpg" are variables from the dataframe mtcars. I understand that I'm passing strings - if I knew how to do it correctly, I wouldn't ask ;) this is for the purpose of explaining the problem
Answer: You have to pass a formula object to lm function. But you give characters in input of myLM.
You can change your function in this way
myLm = function(x,y) {
    fit = lm(formula(paste(x,"~",y)), data=mtcars)
}
myLm("cyl","mpg")

You still give characters input but they are converted inside your function myLM
Comment: Is there any general way to convert variable names (passed as strings) to the type "language"? that is, solve the problem without using the formula object.
Comment: What do a call a "language" type ?
Comment: E.g. I want to call a function within myLm that takes the variable names of the dataframe as an input but not via the formula expession
Comment: this expression has the type "language": typeof(quote(length(x)))
But I what I really want is mentioned above
Comment: I'm not sure I understand what you're looking for but anyway hte function `lm` can be called only for a `formula` object.
Comment: OK, it's better to create a different question for another issue. Mark this problem solved
Answer: Why don't you pass a formula object directly:
myLm <- function(f)
    lm(f, data=mtcars)

myLm(mpg ~ cyl)


Can I make this Ruby code faster and/or use less memory?

Question: I have an Array of String objects in Ruby which are made up of words like the one below:
animals = ["cat horse", "dog", "cat dog bird", "dog sheep", "chicken cow"]
I want to convert this to another Array of String objects but with only one animal per element and only unique elements.  I found one way to do this as follows:
class Array
  def process()
    self.join(" ").split().uniq
  end
end

However, if the input array is huge, let's say millions of entries then performance of this will be pretty bad because I'll be creating a huge string, then a huge array and then uniq has to process that huge array to remove duplicate elements.  One way I was thinking of speeding things up was to create a Hash with an entry for each word, that way I'd only process each word once on the first pass.  Is there a better way?
Comment: If possible set the encoding to ASCII-8BIT to reduce the amount of memory.
Comment: @muistooshort You're right, I was not quite correct (and my example was completely wrong—in fact, `ñ` can't be encoded in ASCII_8BIT). However, "use ASCII_8BIT to save memory" is still terrible advice, unless OP is sure he'll never encounter any characters that aren't ASCII. In Ruby `Encoding::ASCII_8BIT` is intended for raw binary data (it's an alias for `Encoding::BINARY`), not text. It would be a very, very special corpus for which ASCII_8BIT would give a more than negligible advantage over UTF8.
Comment: @steenslag That's bad advice. In UTF-8, every [ISO 8859-1](http://en.wikipedia.org/wiki/ISO/IEC_8859-1) (a.k.a. Latin 1) character is encoded as 8 bits (hence the name). ISO 8859-1 includes the entire ASCII character set (and is ASCII compatible, i.e. `ñ` is `0xF1` (`0b11110001`) in ASCII, ISO 8859-1 and UTF-8). Using ASCII-8BIT will not save any memory.
Comment: @Jordan: Um, no. UTF-8 is a variable length encoding system where having the right bit set means "this character isn't finished yet so keep going to the next byte". `"\xf1"` is not valid UTF-8 at all. The UTF-8 representation of `ñ` is in fact `\xC3\xB1`. They do overlap in the (7-bit) ASCII range though.
Comment: @Jordan: A UTF-8 `ñ` can be encoded in binary just fine, it just takes two bytes. If your source text is in one of the 8859 or Windows-CP encodings then that `ñ` (assuming it is available at all) will only take one byte if the string is treated as binary. So, if your source text is UTF-8 and contains non-ASCII characters then switching to binary won't save anything; if your source text is in ASCII or an 8-bit encoding and contains non-ASCII characters then bypassing UTF-8 could save you quite a bit of memory. Reading the data in binary could  save some time when reading too.
Comment: @muistooshort Like I said, a very special corpus. At any rate it's a really premature optimization.
Comment: The very special corpus I have tried this with was DNA encoding - just four chars. I don't know much about encodings and it was a few years ago, and not production code. I remember saving about 50% memory, but I can't reproduce the results on Ruby 2.1.3. So maybe Ruby is optimized by now, and my advice is indeed useless.
Comment: @steenslag: I don't know if I'd say useless. It really depends on the corpus in question. Optimization is a bit of a black art and the answer is usually some variation of "it depends".
Comment: Have you tried using `flat_map(&:split).uniq` or variants off that?
Comment: Yeah, performance was on a par with the best ones here but not as good as the original
Comment: @steenslag You could have saved another 75% of that memory by encoding each DNA base in two bits. ;) Anyway, the characters `A`, `C`, `G` and `T` have the same encoding in ASCII and UTF-8, which doesn't have anything to do with Ruby being optimized or not. Maybe you were thinking of UTF-16 or UTF-32?
Answer: You've got the right idea. However, Ruby has a built-in class that's perfect for building sets of unique items: Set.
animals = ["cat horse", "dog", "cat dog bird", "dog sheep", "chicken cow"]

unique_animals = Set.new

animals.each do |str|
  unique_animals.merge(str.split)
end
# => cat
#    horse
#    dog
#    bird
#    sheep
#    chicken
#    cow

Or...
unique_animals = animals.reduce(Set.new) do |set, str|
  set.merge(str.split)
end

Under the covers Set actually uses a Hash to store its items, but it acts more like an un-ordered Array and responds to all of the familiar Enumerable methods (each, map, select, etc.). If you need to turn it into a real Array, though, just use Set#to_a.
Comment: @conorgriffin: `set += array` is probably going to be more expensive than `set.merge(array)` due to all copying.
Comment: I tried this out and in practice it doesn't seem to perform better.  My benchmark results are here:
      user     system      total        real
 New:
  0.000000   0.000000   0.000000 (  0.003199)
 Old:
  0.000000   0.000000   0.000000 (  0.000267)
Comment: I'm not surprised given the very small sample. I recommend the [benchmark-ips](https://github.com/evanphx/benchmark-ips) gem, which usually gives much smarter results for code like this. It shows the optimized version is 50x faster. https://gist.github.com/jrunning/2bf920bd438336c2be48
Comment: P.S. Don't take this the wrong way, but your Ruby style is kind of... weird. For one thing, in idiomatic Ruby it's very rare to see empty parentheses in method calls or definitions (i.e. prefer `str.split` over `str.split()`). GitHub maintains a [Ruby Styleguide](https://github.com/styleguide/ruby) that I highly recommend.
Comment: Sorry, yeah I'm new to Ruby so I'm still getting to grips with leaving brackets out and not explicitly returning :)
Comment: Hmmm, I commented on your gist.  Are you missing `|times|` for the older method in the Benchmark?
Comment: Good eye. That should be omitted for both since I'm not using it. I don't *think* it would change the result but I'm not at a computer anymore so I can't check just now.
Comment: :o/ turns out it makes the difference.  Removing `|times|` from the first method results in the new method being ~2.5x slower than the old one.  The new one probably uses less memory for large inputs but it's not faster...
Comment: Ha. I guess it's just not my day!
Answer: Surprisingly (maybe), I don't think you'll be able to go faster than you present code does. I think your code is the fastest and the most readable at the same time. Here is why: your code expresses a pretty good high level algorithm that can be directly mapped into Ruby high level methods. These methods are optimized and compiled. Good luck implementing faster ones in pure Ruby. In any case, I am by no means a Ruby guru, and I would be very interested to see a more performant solution on reasonable size arrays.
Jordan and Nathaniel implemented solutions that are indeed more granular and that process the input array iteratively "by hand". While this may use less memory, it won't be as fast as Ruby's uniq. But if you experience memory problems with large arrays (or performance problems when you reach some threshold), of course you should consider implementing variations on those. Here is mine:
def process
  distincts = Hash.new
  self.each { |words| words.split.each { |word| distincts[word] = nil }}
  distincts.keys
end

This is Jordan's solution, using a Hash instead of a Set. That's what you intended to use. Directly using a Hash will eliminate the overhead of maintaining the Set (or so I suppose), and should be noticeably faster. A slightly even faster solution might be:
def process
  distincts = Hash.new
  self.each { |words| words.split.each { |word| distincts[word] = :present unless distincts[word] }}
  distincts.keys
end

Again, I'm not sure about that (I'm sorry, I can't test all that easily right now). Anyway, I suspect one of these two to be closer to your original code's performances, but I doubt it will overcome it (again, until you hit a certain input size).
Comment: This is better than the other suggestions, it's still slower than my original method though.  See the gist https://gist.github.com/conorgriffin/0a6cecc8f0ebf5c3ca63
Comment: Yes, I am not surprised. As I said, you'll hardly find a better solution than your first thought. Even on very large arrays (and as long as memory space is not a problem), this "Hash version" is unlikely to perform better than yours, though I think it will equal it from the moment it reach a certain array size. Anyway, your implementation is definitely the right choice if memory usage is not an issue.
Comment: This is a very thoughtful answer, Patrice. Your intuition about using Hash instead of a Set was correct, by the way. I benchmarked it and the the original method was still fastest, with the Hash and Set methods 1.7x and 2.9x slower, respectively. https://gist.github.com/jrunning/2bf920bd438336c2be48
Answer: Why not process each array element yourself?
for each element in [...]
  if the element does not contain spaces
    insert it into the result array
  else
    split it up and insert its parts in the next position ahead
  end
end

The following is a ruby implementation:
class Array
  def process
    d = dup
    d.each_with_object([]).each_with_index do |(element, array), index|
      if !element.index " "
        array << element if !array.include? element
      else
        d.insert index+1, *(element.split)
      end
    end
  end
end

["cat horse", "dog", "cat dog bird", "dog sheep", "chicken cow"].process
=> ["cat", "horse", "dog", "bird", "sheep", "chicken", "cow"]

Advantages:

You don't have to process long strings
As close to linear time as possible (see disadvantages)
Maintains element order

Disadvantages:

Slightly slower than linear time (due to how strings are split and inserted ahead)

That said, it's a hell of a lot faster than join(" ").split().uniq (fewer loops). But then it's faster in a practical sense, not a scientific sense.
Comment: "A hell of a lot faster in a practical sense"? I seriously doubt that. I suspect it would be (a lot) slower than OP's solution, and most probably slower than Jordan's one. Array searches and insertions will be serious bottlenecks here.
Comment: I'm afraid your solution is much slower (5x) than the original one
Comment: Huh. I never benchmarked it. It is less iteration-heavy.
Answer: I've tried various methods suggested by others here but I've come up with two that are faster than the others suggested here but not as fast as the original unfortunately.
  # This one moves through the original Array using inject to process
  # each element containing space-separated words and appending them
  # to a new array.  Finally uniq is called to remove duplicate words
  def process_new_4
    self.inject([]) {
        |array, words|
      array.push(*words.split)
    }.uniq
  end

  # This one uses the flat_map method of Array to flatten itself, each
  # element is split in case it contains more than one word, then the
  # flattened array has duplicate elements removed with uniq
  def process_new_3
    self.flat_map(&:split).uniq
  end

Comment: Look at that, both of them use Ruby's `uniq`! These are not really other methods. Well, only other methods for splitting strings. You will find dozens other ways to split strings in Ruby, but the real work is done in the `uniq` part. This is were all other implementations will fall short.
Comment: By the way, did you try on very big arrays to see if the gap is still significant?
Comment: I've run several tests, some with 5,000-30,000 elements (containing 1-5 words per element) and some with 1,000,000 elements (again with 1-5 words per element).


Elasticsearch range unique aggregations doc

Question: Elasticsearch 2.1.1.
The index contains records about athlete's jumps. Each athlete has several attempts to make a jump.
The document has the following structure:
<code>{
   'event_at' : '2015-01-01T12:12:10', - date of jump
   'user_id' : 2142, - athlete's id
   'distance' : 4 - result
}
</code>
It's necessary to get the following result:
<code>{'distance_range' :
 {'*-5' : 12, - the number of unique athletes with the maximum jump score in the range from 0 to 5
  '6-10': 14,- the number of unique athletes with the maximum jump score in the range from 6 to 10
  '11-15': 5 - the number of unique athletes with the maximum jump score in the range from 11 to 15
 }
}
</code>
I managed to get the maximum value of jumping score for each athlete, but I have no idea how to obtain this result on a higher level.
Using SQL it can be like this:
<code>SELECT `distace_range`, count(*) FROM (
  SELECT
    `user_id`,
    IF(MAX(`distace`) <=5,
      '*-5',
      IF(MAX(`distace`) >= 6 AND MAX(`distace`) >= 10,
        '6-10',
        '11-15'
      )
    ) `distace_range`
  FROM `events`
  GROUP BY `user_id`
) t
GROUP BY `distace_range;
</code>
Comment: What version of Elasticsearch are you using? Did you try pipeline aggregations (https://www.elastic.co/guide/en/elasticsearch/reference/current/search-aggregations-pipeline.html) introduced in Elasticsearch 2.x?
Comment: this problem could be solved easily, if you are willing to store max jump in your document.
Answer: I published a question on the official forum dedicated to the Elasticsearch. At the moment, the problem can not be solved by standard instruments, because  for the following query:
<code>'aggregations' => [
  'distance_range' => [
    'terms' => [
      'field' => 'doc.user_id',

    ],
    'aggregations' => [
      'max_distance' => [
        'max' => [
          'field' => 'doc.distance'
        ]
      ]
    ]
  ]
]
</code>
in the elasticsearch version 2.1 there is no pipeline aggregator  by range or term.
There are several possible approaches for solving this problem:

Create  an additional index containing the maximum result
Use scripts
Sum the result on the client-side

I used the third approach.
The first option has a substantial drawback: to have a relevant additional index it's necessary to control it. Thus, I was not satisfied with this solution.
The second option also has some important limitations:
the complexity of the calculations or impact on the selection significantly affects the access time. Moreover, we have to maintain code in multiple systems.


Using hyperreals to express the interval of uniform convergence of $x^n$ in a closed form

Question: The sequence of functions $f_n: E \rightarrow \mathbb{R}$ where $f(x) = x^n$ converges uniformly to $ g(x) = 0 $ for $E = [0,1-\varepsilon]$, $\forall \varepsilon > 0$. Yet, it doesn't converge uniformly for $[0,1)$, the supremum of all $E$.
Is it possible to use infinitesmials to express the interval of uniform convergence in a closed form? If not, why not? If it is possible to do this, isn't this a great advantage of the hyper reals?
Answer: Here's how I interpret your question:
Can we find a hyperreal number $h > 0$ such that the sequence $f_n^\star$ converges uniformly to the zero function on the hyperreal interval $[0,1-h)$ but does not converge uniformly to the zero function on $[0,1-h')$ for any $h' < h$?
No such hyperreal exists.
It's clear that there is no real number r > 0 such that the sequence f_n converges uniformly to the zero function
on the real interval $[0,1-r)$ but does not converge uniformly to zero on $[0,1-r')$ for any $r' < r$.
Applying the Transfer principle to the sentence asserting the non-existence of real numbers satisfying this property yields a sentence asserting that there cannot be a hyperreal number with this property either.