rsyslogd not monitoring all files in config file

Question: I am not seeing rsyslog pick up all files I am trying to monitor.  I am using the standard config from Ubuntu 12.04 LTS but am adding the contents below to /etc/rsyslog.d/30-logentries.conf.
I only see messages from /var/log/myapp.log and a few system log files that are monitored in /etc/rsyslog.d/50-default.conf being pushed to LogEntries, not the other files I am trying to monitor.
I've verified the following:

My other log files are world readable
My other log files are being written to
LogEntries is receiving log messages from the server
/var/log/syslog sees what LogEntries sees, so the log messages don't appear to be lost by log entries
Restarting rsyslog doesn't fix the issue

Any ideas on what I'm doing wrong?
<code>$ModLoad imfile   # Load the imfile input module
$ModLoad imklog   # for reading kernel log messages
$ModLoad imuxsock # for reading local syslog messages

$InputFileName /var/log/myapp.log
$InputFileTag myapp:
$InputFileStateFile myapp
$InputRunFileMonitor

$InputFileName /var/log/nginx/myapp.log
$InputFileTag nginx-myapp:
$InputFileStateFile nginx-myapp
$InputRunFileMonitor

$InputFileName /var/log/nginx/access.log
$InputFileTag nginx-access:
$InputFileStateFile nginx-access
$InputRunFileMonitor

$InputFileName /var/log/nginx/error.log
$InputFileTag nginx-error:
$InputFileStateFile nginx-error
$InputRunFileMonitor

$InputFileName /var/log/nginx/redir-to-http-myapp.log
$InputFileTag nginx-redir-to-http-myapp:
$InputFileStateFile nginx-redir-to-http-myapp
$InputRunFileMonitor

$InputFileName /var/log/nginx/redir-to-www-myapp.log
$InputFileTag nginx-redir-to-www-myapp:
$InputFileStateFile nginx-redir-to-www-myapp
$InputRunFileMonitor

$InputFilePollInterval 1

$DefaultNetstreamDriverCAFile /etc/syslog.logentries.crt
$ActionSendStreamDriver gtls
$ActionSendStreamDriverMode 1
$ActionSendStreamDriverAuthMode x509/name
$ActionSendStreamDriverPermittedPeer *.logentries.com

$template LogentriesFormat,"guidguid-guid-guid-guid-guidguidguid production %HOSTNAME% %syslogtag%%msg%\n"
*.* @@api.logentries.com:20000;LogentriesFormat
</code>
Comment: Of course right after I post to Serverfault I figure it out.  Even though the ngnix log *files* were world readable, the ngnix log *directory* was not.

Giving rsyslog access to that directory fixed it.

Hope this saves someone time!

I'll post as an answer after 8 hours - rep isn't high enough to do it now.
Comment: Hey Dylan, feel like posting that formal answer? :)
Answer: Unicorn(s) was converting comment to CW....
To get rsyslog process the file, its file must be readable by rsyslog. Even though the nginx log files were world readable, the nginx log directory (<code>/var/log/nginx/</code>) was not. Giving rsyslog access to that directory fixed it.


Remove the "Advanced search" form on the result page?

Question: On Drupal 8, how can I remove the "Advanced search" form on the result page ?
I can hide it with css :
<code>#edit-advanced,
#edit-help-link {
    display: none;
}
</code>
But I would prefer to do it with php or even better with a parameter in admin but I didn't see any parameter related to Advanced search in
<code>/ Administration / Configuration / Search and metadata
</code>
Comment: In older versions, there used to be a permission to access the form "use advanced search". Others would likely advise moving off to Search API instead of core search.
Answer: You need to go to:
<code>admin/people/permissions
</code>
and uncheck the checkboxes for the users that don't need to use the Advanced Search.
Comment: @SébastienGicquel if the user that you use is the admin (uid=1) this is the superuser and can see all in the site.
Comment: I think it is the correct answer since this parameter do exactly what i need. But in my case it is already unchecked. Is there something else i should think of  ?
Comment: You're right : if I visit the website without being loggedin, i don't see the advanced search.


Linux doesn't respond to portforwarded connections

Question: I'm new to this site and I want to apologize in advance for any mistakes, dumb questions, etc. (if any).
I have a networking issue and I hope someone has ideas how to solve it. I'm almost sure it's a simple one.
First of all, let's introduce my network configuration/geometry:
<code>    ------
  (        )             SRV                 PC-A                 PC-B
 (          )     ╔════════════╤══╗    ╔═══╤═══════════╗    ╔════════════╤══╗
(  INTERNET  )═══>║ 188.8.131.52│  ║    ║   │192.168.1.1║═══>║ 192.168.1.5│  ║
 (          )     ╟────────────┘  ║    ║   └───────────╢    ╟────────────┘  ║
  (        )      ║               ║    ║               ║    ╚═══════════════╝
    ------        ║   ┌───────────╢    ╟────────────┐  ║
                  ║   │192.168.0.1║═══>║ 192.168.0.4│  ║
                  ╚═══╧═══════════╝    ╚════════════╧══╝
</code>
SRV and PC-A run on Windows XP Pro SP2. They both have an identical software package which do firewalling, NAT, port forwarding and rewriting.
PC-B runs Arch Linux with no iptables rules, it only uses the hosts.allow and hosts.deny approach. PC-B also has a partition with Windows XP Pro SP2 (fresh install, no other software which interacts with the system, firewall disabled).
<code># iptables -L
Chain INPUT (policy ACCEPT)
target     prot opt source               destination

Chain FORWARD (policy ACCEPT)
target     prot opt source               destination

Chain OUTPUT (policy ACCEPT)
target     prot opt source               destination
</code>
PC-A has rules to do port forwarding and rewriting:
- port 3333 => port 3306 @ 192.168.1.5;
- all ICMP => 192.168.1.5
Now the behaviour:
Case 1) when PC-B runs Windows
- from PC-B I'm able to ping IPs from internet, IPs from 192.168.0.0/24 and IPs from 192.168.1.0/24 networks
- if I launch the MySQL server on PC-B, I can connect to it from SRV (specifying host 192.168.0.4 and port 3333) and also from PC-A (netstat shows an establishd connection from 192.168.0.1 when SRV is connected using port forwarding and rewriting)
- from SRV I can ping PC-B
Case 2) when PC-B runs Arch Linux:
- from PC-B I'm able to ping IPs from internet, IPs from 192.168.1.0/24 and only the 192.168.0.4 IP, but not other IPs from 192.168.1.0/24 network
- if I launch the MySQL server on PC-B, I cannot connect to it from SRV (specifying host 192.168.0.4 and port 3333), only from PC-A
While doing all this tests, SRV and PC-A were running without changes or restarts or something like this. They do correctly their job and running Windows on PC-B prove this. I also did packet inspection with Wireshark and the packets are delivered to Linux machine.
Now the question is what is wrong with the Linux machine? Why when running Windows everything works like it should, but when running Linux it doesn't?
My assumption is that something related to routes is missing.
Probably the system doesn't know how to respond to packets with the source IP = 192.168.0.1 (but why it can ping 192.168.0.4 in this case? ).
The routes are:
<code># ip route show
192.168.1.0/24 dev eth0  proto kernel  scope link  src 192.168.1.5
default via 192.168.1.1 dev eth0
</code>
Comment: I did it by hand :) ... but I only had to print out every character only once and then I "ctrl-c/v"'ed them as I needed.
Comment: you didnt draw those ascii pictures by hand did you?
Answer: Are you able to ssh 192.168.1.5? Did you allow 192.168.0.0/24 in host.allow?
192.168.1.1 is responsible to/from forward the request from 192.168.1.5 to 192.168.0.0/24 because as per routes 192.168.1.1 is gateway of your linux box.
Comment: No, I can't use SSH as well. It seems I can't use any service, be it ssh, mysql, http, ping, or others. Maybe a network monitoring tool (tcpdump? does it intercept packets before ANY other process, firewalls, hosts.allow/deny, etc. ?) could help me to find out if the packets arrive to PC-B.


How can I load custom module JavaScript on content type edit form?

Question: I'm trying to load jQuery on the admin edit form of a content type.
To accomplish this, I developed a module "exclusivetabs" with the following directory structure:
|-- exclusivetabs
    |-- exclusive_tabs.info.yml
    |-- exclusive_tabs.libraries.yml
    |-- exclusive_tabs.module
    |-- js
        |-- cse_banner_header.js

The contents of the relevant files are as follows:
exclusive_tabs.libraries.yml
exclusive_tabs:
  version: 1.x
  js:
    js/cse_banner_header.js: {}
  dependencies:
    - core/jquery
    - core/drupalSettings

exclusive_tabs.module
<?php

/**
 * Implements hook_form_alter().
 */
function exclusive_tabs_form_node_form_alter(&$form, &$form_state, $form_id) {
  /* @var Drupal\Core\Entity\FieldableEntityInterface $node */
  $node = $form_state->getFormObject()->getEntity();

  if ($node->getType() == 'unit_landing_page') {
   /* var_dump($node);*/
    $form['#attached']['library'][] = 'exclusive_tabs/cse_banner_header';
  }
}

cse_banner_header.js
(function($, Drupal) {

/* Add span to wysiwyg button classes for alignment
------------------------------------ */
Drupal.behaviors.calloutControl = {
        attach: function (context, settings) {
                console.log("I'm loaded!");
                $('#callout-link-options .single-link').click(function () {
                        $('input[type="checkbox"]').attr('checked', true);
                        console.log("I'm checked!");
                });
                $('#callout-link-options .multi-link').click(function () {
                        $('input[type="checkbox"]').attr('checked', false);
                        console.log("I'm unchecked!");
                });
        }
};

})(jQuery, Drupal);

The module loads on the specific content type edit form as intended; my trouble is that I haven't figured out how to get the jQuery to load from the cse_banner_header.js file. I also checked the running scripts in the browser, and from what I can tell, the js file does not load on the page.
What am I missing? How can I get the js file to load on the page?
Answer: You need to change this line:
$form['#attached']['library'][] = 'exclusive_tabs/cse_banner_header';

to:
$form['#attached']['library'][] = 'exclusive_tabs/exclusive_tabs';

As your library name is exclusive_tabs and not cse_banner_header the correct way is 'your_module/library_name' check Adding stylesheets (CSS) and JavaScript (JS) to a Drupal 8 module.


MySQL - Order By column values, group according other column

Question: Name    1-3    4-6   7-9
------------------------
Dan       0      3     4
Jane      1      6     0
Mike      3      3     3
Dan       2      2     0
Jane      3      4     2
Dan       1      3     0

Here's order that needed to be done.
Name    1-3    4-6   7-9
------------------------
Dan       0      3     4
Dan       1      3     0
Dan       2      2     0
Mike      3      3     3
Jane      3      4     2
Jane      2      2     0

In short, the order by start with the highest number in field 7-9 have then group by the name, then order by again in each group name (in this ex. is Dan & Jane) according field 4-6 and 1-3
Answer: Try this query:
SELECT Name, `1-3`, `4-6`, `7-9`
FROM yourTable
ORDER BY `7-9` DESC, Name, `4-6` DESC, `1-3` DESC

Comment: i think the example is coincidence..
It should be order by `7-9` first
Answer: I think there is typo in your desired result, and try this:
select t1.*
from yourtable t1
join (
  select Name, max(`7-9`) orderby
  from yourtable
  group by Name
  order by max(`7-9`)
) t2 on t1.Name = t2.Name
order by orderby desc, `4-6` desc, `1-3`

Demo Here


Compare array elements,remove the one with the lowest score

Question: There are 200 documents in school db. I must remove each document which has "type":"homework" and the lowest score.
    {
        "_id" : 0,
        "name" : "aimee Zank",
        "scores" :
        [
            {
                "type" : "exam",
                "score" : 1.463179736705023
            },
            {
                "type" : "quiz",
                "score" : 11.78273309957772
            },
            {
                "type" : "homework",
                "score" : 6.676176060654615
            },
            {
                "type" : "homework",
                "score" : 35.8740349954354
            }
        ]
    }

For example,here
    {
        "type" : "homework",
        "score" : 6.676176060654615
    }

must be removed  as score = 6.6 < 35.8
I sorted all the documents like this:
db.students.find({"scores.type":"homework"}).sort({"scores.score":1})

But I do not know how then to remove the doc having the lowest score and type:homework???
 NOTE: how to solve it by not using aggregation method? E.g., by sorting and then updating.
Answer: This can be done in a couple of steps. The first step is to grab a list of the documents with the minimum score by using the aggregation framework with $match, $unwind and $group operators that streamlines your documents to find the minimum score for each document:
lowest_scores_docs = db.school.aggregate([
    { "$match": {"scores.type": "homework"} },
    { "$unwind": "$scores" },  { "$match": {"scores.type": "homework"} },
    { "$group": { "_id":"$_id", "lowest_score": {"$min": "$scores.score" } } } ] )

The second step is to loop through the dictionary above and use the $pull operator in the update query to remove the element from the array as follows:
for result in lowest_scores_docs["result"]:
    db.school.update({ "_id": result["_id"] },
        { "$pull": { "scores": { "score": result["lowest_score"] } } } )

Comment: Hi, Chridam. I'm grateful to you a lot for your quick reply. But unfortunately,it also did not remove the element of array having "type":"homework" and the lowest value in each _id., in each document.
Comment: @sapio_l Any error messages being displayed? Have you tried printing the object `lowest_scores_docs` to see if anything is being returned from the aggregation?
Comment: Yes,I did. The loop does not work,it prints nothing. @chridam
Comment: Now I use another method: db.students.find({"scores.type":"homework"}).sort({"scores.score":1})
But I do not know how to remove the second document having the lowest score and type:homework using update function.  @chridam
Comment: I againly tried your code. Thanks a lot! It worked. But it deletes the min score in scores array, however, I would like to delete an item having minimum score among  "type":"homework". Although you've written { "$match": {"scores.type": "homework"} }, I see it does not take it consider.Why? I've trouble in fix it.
Comment: @sapio_l You are correct, you would need to do another `$match` operation after the `$unwind`. I have thus edited my answer to reflect this change. If this answer was helpful, please consider marking/accepting it for the benefit of other users although there is no obligation for you to do so.
Comment: Thanks a lot,chridam! I also tried to use $match operator,but in wrong place. By the way, do you know how to solve it by sorting and then updating method? I mean not using aggregation method.
Comment: i tweaked your loop, as the the iteration you wrote didnt work for me:

lowest_scores_docs.forEach(function(i, v){ db.school.update({ "_id": i._id }, { "$pull": { "scores": { "score": i.lowest_score } } } ) });
Comment: @kennydust Thanks for your feedback, was the loop you wrote in Python?
Comment: javascript via mongoshell
Answer: import pymongo
import sys

# connnecto to the db on standard port
connection = pymongo.MongoClient("mongodb://localhost")

db = connection.school           # attach to db
students = db.students        # specify the colllection

try:

        cursor = students.find({})
        print(type(cursor))
        for doc in cursor:
            hw_scores = []
            for item in doc["scores"]:
                if item["type"] == "homework":
                    hw_scores.append(item["score"])
            hw_scores.sort()
            hw_min = hw_scores[0]
            #students.update({"_id": doc["_id"]},
             #           {"$pull":{"scores":{"score":hw_min}}})

except:
    print ("Error trying to read collection:" + sys.exc_info()[0])


How are varying degrees of accent notated?

Question: Most music notation give very binary accents for beats (either there or not), but there are many "degrees" of accenting a beat.
One bar of 4 4 time, "one two three four", is equivalent to two bars of 2 4 time, "one two one two."
What makes the difference is the subtle emphasis:
"ONE two three four" is distinguished from "ONE two ONE two."
I would like to know how I could potentially alter this pattern. For example, if I wanted to change my 4 4 rhythm, "ONE two three four", to "one two THREE four," or "ONE two three four."
Is there any musical notation for this?
Post Script: Just for anyone's curiosity, if no such notation exists and I'm forced to create it for my own use, my system would involve superscripting any notes with numbers (1 being most accented, 2 being less  so, etc.).
Comment: The levels of accenting you describe are referred to in [A generative theory of tonal music](https://en.wikipedia.org/wiki/Generative_theory_of_tonal_music), though I don't recall them using conventional notation.
Comment: Beware--at least for piano, tiny numbers next to notes (i.e. at least resembles superscript) are for fingering.
Answer: Not sure if you'll like this answer, but the examples you're giving for the problem are actually the answers to your question.
There are a couple ways the composer can impact stress with the meter:

Orchestration: give players accent, staccato, legato, marcato, etc; to impact the stress a listener will feel on any given beat.
Instrumentation: choose which instruments play which parts to change the stress; a trumpet or a snare drum will have a stronger attack than a legato violin, so make stronger attacks on beats you want to feel heavier
Subdivision: often next to or above the time signature, a composer will notate the subdivision that the player is intended to feel. For example: 10 8 (3+3+2+2) versus 10 8 (2+3+3+2)

I think the real answer is that as a composer/arranger, your role is to make the feel apparent through the music. The feel is a compilation of each individual part coming together, not something that is independent of the music for you to notate at a later time.
Answer: If the accent pattern changes often, then just use conventional accents.  Chopin's Etudes op. 10 and op. 25 are full of this.
For varying amounts of accent, also use the "marcato" accents favored by Liszt in e.g. his Transcendental Etudes.
For many finely distinguished degrees of accent (like klangfarbenmelodie or integral serialism), alter the note itself (replace a quarter note with an eighth note and an eighth rest), specify the dynamics (p, mf) for every single note head, etc.  Because now the interpretation of accent is done by the composer rather than the performer.  So make it official.  Remove the performer's interpretive freedom in this regard.
If the accent pattern remains constant for many bars at a time, then notate it explicitly (however you like) for the first three bars, and then write simile.


NSXML Parsing - Distinguishing Nodes

Question: I am trying to extract the doc-num from the following xml using NSXML.  At this point I am able to iterate through all the nodes using the NSXML parser event, but I am trying to distinguish between the doc-num in the input node from the one in the output node.
How can I do this?  I am a bit lost on how to get this to work for my iphone app. Also, is there a simpler way than the event based NSXML?
<code>     <xmt:input>
        <xmt:app-refer>
            <doc-id doc-id-type="docdb">
                <country>MD</country>
                <doc-num>20050130</doc-num>
                <kc>A</kc>
                <date>20050130</date>
            </doc-id>
        </xmt:app-refer>
    </xmt:input>
    <xmt:output>
        <xmt:app-refer>
            <doc-id doc-id-type="epodoc">
                <doc-num>MD20050000130</doc-num>
                <date>20050130</date>
            </doc-id>
        </xmt:app-refer>
    </xmt:output>
</code>
Answer: Here is a tutorial that shows XML parsing using GDataXMLParser.
how-to-read-and-write-xml-documents-with-gdataxml
GDataXMLParser is better than NSXMLParser since latter is slower.
Comment: Excellent! Let me take a look.
Comment: And yes, I believe this will do the trick! Thank you very much.

NSXML Parsing - Distinguishing Nodes


Apache ProxyPass Reverse DNS - Forward all source files?

Question: I've got some websites in the local network, which have no access to the internet.
So I want to set up one machine which has the access, and use it as a reverse proxy.
My apache config looks like this:
ProxyPass "/website1" "http://192.168.0.1/website1"
ProxyPassReverse "/website1" "http://192.168.0.1/website1"

So when I access my public domain /website 1 it redirects me to the website1, but when i click something on there which forwards me to something like /website1/about, it doesn't work, because the sourcecode still says to go to http://192.168.0.1/website1/about, which is obviously not possible from outside of the local network.
So how do I get Apache to forward all files and rewrite the paths?
Or an even better question, is there something better than apache to do an reverse proxy?
complete conf: http://pastebin.com/Mhuv7YzM
Comment: Apache is great for reverse proxy. My question is how the rest of the VirtualHost looks like, can you provide us with it?
Comment: @Orphans added, but really nothing special there
Comment: Please check my answer
Answer: You have two options depending on what you backend does.
If the backend server modifies html links with the name of the requested host you can just add:
ProxyPreserveHost on

If you want to modify the contents of "fixed" htmnl links inside the responses you will also need "mod_proxy_html" functionality, which is a mod_proxy submodule specific for this.
mod_proxy_html
Answer: You don't. ProxyPassReverse is only intended to rewrite redirects, not paths somewhere in the body of files. That would require pretty much complete knowledge of the content format, like HTML, SOAP, whatever, to know where paths are to be expected and replaced (like in  for HTML, but also <link>,


How to specify  in wix .wxs file

Question: I want to specify property as restricted property in Wix installer,  in wix .wxs file.
  <Property Id="PROP1">
     <RegistrySearch Id="Prop1"
                     Root="HKLM"
                     Key="SYSTEM\CurrentControlSet\Services\mysvc"
                     Name="installers"
                     Type="raw" />
  </Property>
  <Property Id="PROP2">
     <RegistrySearch Id="Prop2"
                     Root="HKLM"
                     Key="SYSTEM\CurrentControlSet\Services\mysvc"
                     Name="DisplayName"
                     Type="raw" />
  </Property>

Any idea?
Wanted to make PROP1, PROP2 private / secured.
Tried with making them as lowercase but RegistrySearch doesn't accept it:

error CNDL0012 : The Property/@Id attribute's value, 'Prop1', cannot
  contain lowercase characters.

Since this is a search property, it must also be a public property.  This means the Property/@Id value must be completely uppercase.
Comment: What behavior are you trying to ensure? It sounds like you want to prevent a user from overriding this property's value, but SecureCustomProperties doesn't have that effect. (If anything, it's closer to the opposite.)
Answer: I believe you need to set the attibute Secure="yes" for the Property element in order for the property in question to be added to the SecureCustomProperties list in your compiled MSI file.
Sample:
<Property Id="MYPROPERTY1" Secure="yes" Value="SomeValue" />
<Property Id="MYPROPERTY2" Secure="yes" Value="SomeOtherValue" />

The resultant SecureCustomProperties value in the compiled MSI (with two auto-generated properties as well): MYPROPERTY1;MYPROPERTY2;WIX_DOWNGRADE_DETECTED;WIX_UPGRADE_DETECTED
Your Case:
So in your case something like the below (I set the property value to 0 in case the registry search finds nothing - then I have a default value):
<Property Id="PROP1" Secure="yes" Value="0" >
   <RegistrySearch Id="Prop1"
                   Root="HKLM"
                   Key="SYSTEM\CurrentControlSet\Services\mysvc"
                   Name="installers"
                   Type="raw" />
</Property>

The SecureCustomProperties list all the properties that can be sent to deferred mode - which runs elevated - when the installing user is not an administrator, but a standard users who is installing with elevated rights. For a good technical overview of the issue, maybe check out: Restricted Public Properties.

Digression:
And now, the mandatory digression: there was a case a while back when I needed to be able to override the value of SecureCustomProperties myself for some reason - rather than having it auto-generated based on all the properties with the Secure="yes" flag set.
For my life I cannot remember the particulars of the reasoning behind the need right now. Maybe Chris or Phil will remember / know of similar cases. I think it related to properties being added auto-magically to my MSI by WiX, but they were not set secured and I needed to make them secure in order to reliably access their values in deferred mode. I don't remember what WiX feature it related to.
Comment: Thanks for answer, can I ensure that the variable is not public, using cmdline on MSI.
Comment: There is the [MsiHiddenProperties Property](https://msdn.microsoft.com/en-us/library/windows/desktop/aa370308(v=vs.85).aspx) - please read the linked documentation thoroughly. You can add a [WiX property](http://wixtoolset.org/documentation/manual/v3/xsd/wix/property.html) to this list of hidden properties by setting the attribute `Hidden="yes"`. [This Symantec article seems to be a good summary of prevening sensitive information getting into the log file](https://www.symantec.com/connect/blogs/preventing-confidential-information-being-written-log-file).
Comment: And another link for safekeeping: https://www.advancedinstaller.com/forums/viewtopic.php?t=30546.

How to specify  in wix .wxs file


Draw a graph which is both cycle and complete and a graph which is cycle but not bipartite (Must use 2 different graphs)

Question:
Draw a graph which is both cycle and complete and a graph which is cycle but not bipartite (Must use 2 different graphs)

I can't seem to find the answer to this question.
This is what I drew
This graph is the answer to both graphs asked but I can't think of a second different one.
And does a edge in a cycle graph only have 2 degrees or can it have more than 2?
Answer: A cycle is not bipartite if and only if it is odd. Just use a cycle of length $5$.
Every vertex in a cycle has degree $2$.
Answer: A graph (in fact the only) which is both a cycle and complete is $3$-cycle or a triangle. A graph that is a cylce but not complete is a $2k+1$ cycle for any positive integer $k$.
Here are the two graphs desired:
Answer: As they told you, a cycle with $2k$ vertices is always bipartite.
But if you're wondering why, then you can simply distribute the "odd" vertices into a set $X$ and the "even" vertices into a set $Y$
i.e. $X=\{v_1,v_3,v_5,\cdots, v_{2k-1}\}$ and $Y=\{v_2,v_4,v_6, \cdots v_{2k}\}$ and that is a bipartite graph.
Comment: Odd is not bipartite. Even is.
Comment: Oh yes ofcourse, didn't give it a second thought.


Como passar o valor de uma variável para maiúscula ou minuscula?

Question: Eu tenho um script que recebe uma varável ao executar, por exemplo:
./myscript OLA

o conteúdo de myscript:
#!/bin/bash

if [ -z $1 ]
then
  echo "Por favor escolha uma opção:"
  echo "OLA - Faz qualquer coisa"
  echo "OLE - Faz outra coisa"
  ...
else
  echo "Vou fazer alguma coisa consoante a variável."
  if [ $1 = "OLA" ]
  then
    echo "Olá amigo."
    ...

Eu quero que ./myscript ola ou ./myscript OlA, etc também funcionem. Como eu posso passar o $1 para maiúscula para a comparação? Já agora e para minuscula?
Comment: https://stackoverflow.com/questions/2264428/how-to-convert-a-string-to-lower-case-in-bash
Answer: Como havia mencionado nos comentários, existe uma expansão shell para fazer isso: ${variable^^} vai transformar o texto em variable para caixa alta.
Vou copiar os exemplos desta resposta no StackOverflow internacional, porque ele mostra inclusive comportamentos que eu não conhecia:
$ string="a few words"
$ echo "${string^}"
A few words
$ echo "${string^^}"
A FEW WORDS
$ echo "${string^^[aeiou]}"
A fEw wOrds

$ string="A Few Words"
$ declare -u string
$ string=$string; echo "$string"
A FEW WORDS

a expansão com um único circunflexo ${var^} transforma a primeira letra em caixa alta
a expansão com dois circunflexos ${var^^} transforma todas as letras em caixa alta
a expansão com uma expressão blob após os circunflexos transforma os caracteres que casam com o padrão

Sobre essa expressão com padrão, note que, se você usar com um único circunflexo, ele só colocará em caixa alta se o primeiro caracter bater com a expressão:
$ var=abcd
$ echo ${var^[bcd]}
abcd
$ echo ${var^^[bcd]}
aBCD
$ echo ${var^[abcd]}
Abcd

Você pode entender a expansão com circunflexo um caso especial da expansão com circunflexo + padrão:
$ echo ${var^^?}
ABCD
$ echo ${var^?}
Abcd

A vantagem dessa alternativa perante usar awk, tr, perl é que não se inicia um novo processo, a execução toda é feita "diretamente" pelo Bash.

Para transformar em minúsculas, a expansão usa vírgulas no lugar do circunflexo. Todo o resto se comporta de maneira análoga:
$ string="A FEW WORDS"
$ echo "${string,}"
a FEW WORDS
$ echo "${string,,}"
a few words
$ echo "${string,,[aeiou]}"
a FeW WoRDS

$ string="A Few Words"
$ declare -l string
$ string=$string; echo "$string"
a few words

Por curiosidade, notou que existe uma declaração especial de variável que a transforma em caixa alta ou caixa baixa na simples atribuição? Isso é feito através do declare da variável.
Na resposta de onde peguei os exemplos não encontrei nada que referenciava o porquê do padrão dos argumentos do declare, mas achei isso que é extremamente digno de nota:

The declare options change the attribute of the variable, but not the contents. The reassignments in my examples update the contents to show the changes.

Em tradução livre:

As opções do declare mudam o atributo da variável, mas não seu conteúdo. As reatribuições nos exemplos atualizam o conteúdo para mostrar as mudanças.

Então, por que usar -u para caixa alta e -l para caixa baixa? Se você pensar no inglês, fica mais fácil lembrar:

caixa baixa, lowercase, -l
caixa alta, uppercase, -u

Ficam então esses mnemônicos para ajudar na memorização das flags da declaração de variáveis.
Answer: Pode usar awk para fazer isso. Segue exemplo. Coloque a linha que converte no seu script, antes de fazer o teste. Depois teste com $VAR ao invés de $1
   #!/bin/bash
    #$VAR recebe $1 convertido para maiusculas
    VAR=$(echo $1 | awk '{ print toupper($1) }')
    echo "Variavel em maiuscula: $VAR"

Comment: @JeffersonQuesado - não consegue colocar uma resposta aí com sem precisar de outro processo? Seria melhor de qualquer forma.
Comment: Não está errado, porém não é necessário criar um novo processo para fazer isso.
Comment: na verdade, em shell, é quase certeza que vai se criar um novo processo - senão  pra isso, pra quase qualquer coisa - awk talvez seja overkill, mas por outros motivos.
Comment: @jsbueno, há uma expansão de variável que faz isso na Bash, que não faz a criação de um novo processo
Comment: Nas referências que estou encontrando, se usa `awk '{ print toupper($0) }'`, não `$1`. Por exemplo: https://stackoverflow.com/q/14021899/4438007
Comment: Testei com `awk '{ print toupper($0) }'` e com `awk '{ print toupper($1) }'`, obtive os mesmos resultados
Comment: @jsbueno, [Já pus](https://pt.stackoverflow.com/a/424156/64969)


Stirling Numbers $ \sum_{j= m}^{n-r} \binom{n}j {j \brace m} {n-j\brace r} = \binom{m} {m+r} {n\brace m+r} $ Combinatorical Proof or Algebraic

Question: $$\sum_{j= m}^{n-r} \binom{j}n {j \brace m} {n-j\brace r} = \binom{m} {m+r} {n\brace m+r}$$
I am trying to proof some identies from concrete mathmatics page 265. But i cant get nowhere. No clues where to start, I have found a proof involving Euler's Formula for Stirling Number. The Books gives them: Like here there are not event a hint how to show it.
update:
Well there is a clue in other book: both sides counting pair $(P_1,P_2)$ with $P_1 (k+r)$ partitions of $\{1,\ldots,n\}$ $P_2$ subfamily of $k$-blocks of $P_1,\ldots$ what ever this means
Comment: I started to typeset a proof when I noticed that this identity appeared here at [MSE](https://math.stackexchange.com/questions/2477859) some months ago last year.
Comment: well index error fixed! Now it makes sense :)
Comment: Are you sure of $m\choose m+r$ for $r>-1$????
Comment: And are you sure $j\choose n$? Check the whole expression and modify it for helping you.
Comment: Appears to hold with the binomial coefficient arguments exchanged.
Answer: This combinatorial Identity represents a bicolouring of a partition
\begin{eqnarray*}
\color{red}{(r_{1,1} \cdots ) (r_{2,1} \cdots )\cdots (r_{m,1}\cdots) } \color{blue}{(b_{1,1} \cdots ) (b_{2,1} \cdots )\cdots (b_{r,1}\cdots) }
\end{eqnarray*}
where the red partiton is of $k$ elemnets into $m$ blocks & the blue partition of $n-k$ elements into $r$ blocks.
Partition $[n]$ into $k+r$ blocks then colour $k$ of the blocks red and $n-k$ of them blue.
Choose $n-j$ elements from $[n]$, colour them red and partition them into $m$ blocks. Now colour the other $j$ elements blue and partition them into $r$ blocks. Thus
\begin{eqnarray*}
{{n}\brace r+m}\dbinom{r+m}{m}=\sum_{j =m}^{n-r}{{j}\brace r}{{n-j}\brace m}\dbinom{n}{j}.
\end{eqnarray*}
Comment: wow! This is a very nice interpretation


Is something wrong in my solution?

Question: We have $f:(-1,\infty)\rightarrow\mathbb{R},f(x)=\frac{x}{x+1}$ and need to show that $a_n=\sum_{k=1}^n f(k)-\int_0^n f(t)dt$ is bounded.
Here is all my steps:
$f'>0\Rightarrow f$ is strictly increasing. Therefore $f(c_k)>f(k)$
where $f(c_k)=\int_k^{k+1}f(x)dx,\forall c_k\in[k,k+1]$.
By the way: $$\sum_{k=1}^n f(k)<\int_1^{n+1}f(x)dx$$
$\Rightarrow a_n<\int_1^{n+1}(1-\frac{1}{x+1})dx-\int_0^n f(t)dt$

It is correct what I wrote of this?
How can I continue from here?
Answer: $$
use \; :\int_{0}^{n}f(t)dt=\sum_{1}^{n}\int_{k-1}^{k}f(t)dt\; \; (1)\\then :f\;is \; increasing \;so:f(k-1)\leq f(t)\leq f(k)\\f(k-1)\leq \int_{k-1}^{k}f(t)dt\leq f(k)\\finally :0\leq a_{n}\leq \sum_{1}^{n}f(k)-f(k-1)=f(n)-f(0)\underset{\infty }{\rightarrow}1
$$
Comment: mounir what is wrong in my solution?
Comment: you can continue like this to obtain the same result :
$$
\int_{1}^{n+1}f(t)dt-\int_{0}^{n}f(t)dt=\int_{n}^{n+1}f(t)dt-\int_{0}^{1}f(t)dt\\ \leq f(n+1)-f(0)\underset{\infty }{\rightarrow}1
$$
Comment: mounir how you arrived at that conclusion: $\leq f(n+1)-f(0)$ ?
Comment: f is increasing so $ f(t) \leq f(n+1) $ if you integrate from n to n+1 , you obtain $ \int_{n}^{n+1}f(t)dt \leq \int_{n}^{n+1}f(n+1)dt=f(n+1)\int_{n}^{n+1}dt=f(n+1) $
Comment: Getting increasingly accurate approximations to $\int_n^{n+1} f(x) dx$ in terms of $f$ and its derivatives leads to the Euler-Maclaurin summation formula.
Answer: There is nothing wrong so far. Keep evaluating your right-hand side: $\int \limits _1 ^{n+1} f \Bbb \space d t - \int \limits _0 ^n f \Bbb \space d t = \int \limits _n ^{n+1} f \space \Bbb d t - \int \limits _0 ^1 f \space \Bbb d t = 1 + \ln {n \over n+1} - 1 + \ln 2 = \ln 2 + \ln {n \over n+1}$. Now note that $\frac 1 2 \leq \frac n {n+1} < 1$, so $\ln 2 + \ln {n \over n+1} \leq \ln 2 + \ln 1 = \ln 2$, which is an upper bound for your $a_n$.
Answer: $$a_n=\sum_{k=1}^{n}f(k)-\int_{0}^{n}f(t)\,dt = \sum_{k=1}^{n}\frac{1}{k+1}-\int_{0}^{n}\frac{dt}{t+1}\,dt=H_{n+1}-1-\log(n+1)$$
is negative because:
$$ \int_{k-1}^{k}\frac{dt}{t+1}=\int_{k}^{k+1}\frac{dt}{t}\in\left(\frac{1}{k+1},\frac{1}{k}\right) $$
since $g(t)=\frac{1}{t}$ is a positive decreasing function on $\mathbb{R}^+$. On the other hand:
$$ a_{n+1}-a_n = \frac{1}{n+2}-\log\left(1+\frac{1}{n+2}\right)\geq 0$$
gives that the sequence $\{a_n\}_{n\geq 1}$ is increasing, and the Hermite-Hadamard inequality gives:
$$\begin{eqnarray*} a_n &=& \sum_{k=1}^{n}\left(\frac{1}{k+1}-\int_{k}^{k+1}\frac{dt}{t}\right) \geq \frac{1}{2}\sum_{k=1}^{n}\left(\frac{1}{k+1}-\frac{1}{k}\right)\geq -\frac{1}{2}.\end{eqnarray*} $$
We have, indeed,
$$ \lim_{n\to +\infty}a_{n} = -1+\gamma = -0.422784335\ldots $$
where $\gamma$ is the Euler-Mascheroni constant.

Is something wrong in my solution?


Factor Analysis of Count Data

Question: I am new to factor analysis.  I inherited a project at work from another team.  They took 9 variables that are all Poisson-distributed count random variables and ran a "regular" factor analysis in Stata/SPSS (they did not specifically account for this being count data).  The four factors they obtained are each normally distributed continuous variables.
My question is:
Is what they did correct, or are there special factor analysis methods for count data?
Should I be concerned that the factors are a totally different distribution than the original data?
The next step in the project is to set up regression models for each of the factors as the DV.  Obviously, if the factors had been in the same family as the original count data, I would be running Poisson or NBD regressions, but after this transformation, I am running linear regressions.  Not sure which is the right way to go.
I'd appreciate advice and information that would help me learn more about this.  Stata specific information is a plus.
Comment: I think that one may use classic (linear) factor analysis with count data. But... think where the origin of the data cloud should be placed. Is it correct to center the variables (to place origin at the centroid) when the data are counts (and so count 0 looks as the natural origin)? What do you think about it? Wouldn't [SSCP or cosine matrix](http://stats.stackexchange.com/a/22520/3277) be the better input in your factor analysis than their corresponding centered versions - covariance or correlation matrix?
Comment: If you need 4 factors to represent 9 variables, you aren't gaining much and you may be giving up  a lot. So ... I'm not sure that I would use the factors rather than the original variables - unless the factors make a lot of sense.
Answer: Poisson data is normally distributed when the rate parameter $> 10$ish.
If even one of the count variables included in the factor analysis has an average rate close to 10, it seems straightforward that the resulting mixture of all those count variables could take on this distribution given the right circumstances.
Furthermore, even binary random variables, when several are averaged will begin to approximate a normal distribution
Still, if the variables input into the factor analysis don't relate linearly to each other, they're not going to load heavily, and you could miss out on predictive power. I.e., at times, $X$ might not load, but $X^2$ or $\text{log}(X)$ could

Factor Analysis of Count Data


nextProps always identical to this.props in componentWillReceiveProps, even when the props have changed

Question: I have a component in my React app that renders a total value for the user. When that value goes up, I want to play a noise. I figured that within the component that displays the total would be a good place to play that noise from.
So I added a componentWillReceiveProps method to the component, and in it, I calculate two totals: total is calculated from this.props and nextTotal is calculated from nextProps.
To my surprise, even when the values change, and the totals change, nextTotal and total are always the same. So the conditional that I want firing when the total goes up never happens.
I wrote up a simple, single-component example. JSfiddle.
var Hello = React.createClass({
  componentWillReceiveProps: function(nextProps) {
    var total = 0;
    this.props.vals.forEach(val => total+= val);

    var nextTotal = 0;
    nextProps.vals.forEach(val => nextTotal+= val);

        console.log(total, nextTotal)

    if (nextTotal > total) {
            //never runs
            console.log('moving up');
        }
  },
  render: function() {
    var total = 0;
    vals.forEach(val => total+= val)
    return (

{total}

    )
  }
});

var vals = [1, 21, 452, 123];

setInterval(renderReact, 1000)

function renderReact() {
    vals.push(10);
  ReactDOM.render(
    <Hello
      vals={vals}
    />,
    document.getElementById('container')
  );
}

As you can see, every second it adds 10 to the vals array, which means the total moves up by 1. But if you open the console, you can see that total and nextTotal are always the same, and moving up never gets logged.
I'm clearly misunderstanding something, and if anyone could explain what my misunderstanding is, and how I should achieve what I'm going for, that would be fantastic.
Comment: You are passing the array directly to the element. `this.props.vals` and `nextProps.vals` are referencing the same object.
Comment: @JohnRuddell there is a setInterval that is calling renderReact every second
Comment: why not try logging the two arrays? check it out you keep pushing ten to both of them...https://jsfiddle.net/ydaso4cs/2/ which are the same thing...
Comment: not only are you referencing the same array, your component isnt updating since you are calling the render once. I dont see any code that is causing an update.
Comment: Perhaps reading this will help: https://facebook.github.io/react/blog/2016/01/08/A-implies-B-does-not-imply-B-implies-A.html
Comment: ah my bad I thought I read setTimeout. the array reference is the issue though
Comment: try adding a new variable like so `let valsCopy = vals.slice(); valsCopy.push(10); ` and then in the return `vals={valsCopy}`
Answer: As noted in the comments (by @PitaJ), your problem is that you're passing in an array the first time, and then ALTERING the array - rather than calling with a new property. You've reached into the object your component is holding a reference to as its existing property and changed the contents of it.
In your fiddle, try this:
function renderReact() {
    vals.push(10);
  ReactDOM.render(
    <Hello
      vals={vals.concat([])}
    />,
    document.getElementById('container')
  );
}

Passing a copy of the array in as your prop each time, you'll see they differ appropriately.
This is actually a non-trivial source of error in using react, and can crop up even when using redux with it if reducers aren't carefully written. Using immutable data structures is one way to avoid it.


PHP array delete by value (not key)

Question: I have a PHP array like so:
$messages = [312, 401, 1599, 3, ...];

Given that the values in the array are unique, how can I delete the element with a given value (without knowing its key)?
Comment: @Adam Strudwick But if you have many deletions on this array, would it be better to iterate it once and make its key same as value?
Comment: Same question : http://stackoverflow.com/questions/1883421/removing-array-item-by-value
Comment: posible duplicate of [PHP Delete an element from an array](https://stackoverflow.com/questions/2448964/php-how-to-remove-specific-element-from-an-array)
Answer: Using array_search() and unset, try the following:
if (($key = array_search($del_val, $messages)) !== false) {
    unset($messages[$key]);
}

array_search() returns the key of the element it finds, which can be used to remove that element from the original array using unset(). It will return FALSE on failure, however it can return a false-y value on success (your key may be 0 for example), which is why the strict comparison !== operator is used.
The if() statement will check whether array_search() returned a value, and will only perform an action if it did.
Comment: Even though this is valid, you should avoid assigning values in statements like that. It will only get you into trouble.
Comment: Would $messages = array_diff($messages, array($del_val)) work too? Would it be better in performance?
Comment: If the value you're searching for has a key of `0` or any other falsey value, it won't unset the value and your code won't work. You should test `$key === false`. (edit- you got it)
Comment: @Adam Why not test it out? My feeling is that `array_diff()` would be slower as it's _comparing two_ arrays, not simply searching through _one_ like `array_search()`.
Comment: Note that this will not reset array keys.
Comment: If you need to reorder the keys then change `unset` to `array_splice`.
`array_splice($messages, $key, 1);`
Comment: Just tried it with an array with five 0 values and the code above removed just the first 0 element (with index=0), while the other elements with indexes 1, 2, 3 & 4 remained.
Comment: @adam Exactly what @evan said. If the `key = 0` for the $del_val, you will not unset it. Also, it can be very difficult to maintain such assignments.
Comment: I think this shuold be done in a while loop because the value can occur multiple times.
Comment: For >php5.3 : $array = array_filter($array, function($i){return $i != $value;});
Comment: To remove all instances not just the first found element we could use **while**

`while (($key = array_search($del_val, $messages)) !== false) {
                    unset($messages[$key]);
                }`
Comment: Note that this and `array_filter` will result in an array without incremental keys, so if it's JSON encoded it will be converted to an object. To avoid this use `array_values` after.
Comment: I've amended my answer; the `!==` false will check for the return type now, too. @Adam, please change _your_ code to prevent any errors you might get in the future.
Comment: To catch keys that are 0, the following syntax works:

if(FALSE !== $nullKey = array_search($del_val, $messages)){ ... }
Comment: it should be `array_search($value, $array, false)` to catch also matches where without variable type matching. Ex. `"123" == 123`
Comment: @adlawson It's a pretty standard thing to do. But doing a comparison on it at the same time like is done in this answer is ugly and i'd shift it out.
Comment: Your code will fail if array_search find value at key 0 then variable $key will evoluate to true and then unset($message[$key]) will be unset($message[true]) this will unset random key..
Comment: If you want this to work with associative arrays and remove also multiple values, the just replace the "if" with "while" for a more generic approach:

        while (($key = array_search($value, $data)) !== false) {
            unset($data[ $key ]);
        }
Answer: Well, deleting an element from array is basically just set difference with one element.
array_diff( [312, 401, 15, 401, 3], [401] ) // removing 401 returns [312, 15, 3]

It generalizes nicely, you can remove as many elements as you like at the same time, if you want.
Disclaimer: Note that my solution produces a new copy of the array while keeping the old one intact in contrast to the accepted answer which mutates. Pick the one you need.
Comment: this only works for objects that can be converted to a string
Comment: It's worth noting that for some reason `array_diff` uses `(string) $elem1 === (string) $elem2` as its equality condition, not `$elem1 === $elem2` as you might expect. The issue pointed out by @nischayn22 is a consequence of this. If you want something to use as a utility function that will work for arrays of arbitrary elements (which might be objects), Bojangle's answer might be better for this reason.
Comment: Also note that this method performs a sort internally for each argument to `array_diff()` and thus nudges the runtime up to O(n lg n) from O(n).
Comment: I don't know why, but the `[$element]` in square brackets breaks my code, while `array($element)` is working.
Comment: For force accept string, int or array, the way is:  `return array_diff($array (array)$element)`
Comment: Why create a separate function for one php function? This is overkill because you can just call array_diff directly with the same params.
Comment: It's a way slower than array_search. See @Jack comment: it changes complexity from O(n) to O(n lg n), i.e. for 1000 elements this solution will take ~7 times more cpu time than array_search.
Comment: @KrzysztofPrzygoda: He doesn't know what he is talking about. The complexity of this functions is IMPLEMENTATION and VERSION dependant.
Comment: I agree with Krzysztof Przygoda, this function is **two orders of magnitude** slower than array_search() with 2554 real-world elements.
Comment: to be sure it is iterable use array_values(array_diff($arr1, $arr2));
Comment: This creates a new array. Isn't this a drawback compared to the `unset` solution?
Comment: Doesn't work for me: I use it on an array with 2 elements while the first element will be removed but the elements keep their index but seems to be unreadable: Notice: Undefined offset: 0
Answer: One interesting way is by using array_keys():
foreach (array_keys($messages, 401, true) as $key) {
    unset($messages[$key]);
}

The array_keys() function takes two additional parameters to return only keys for a particular value and whether strict checking is required (i.e. using === for comparison).
This can also remove multiple array items with the same value (e.g. [1, 2, 3, 3, 4]).
Comment: This is the best for arrays that may not contain all unique values.
Comment: @Rodniko in which case you would need `array_values()` as well; the remaining keys are still in the same order though, so technically it's not "unsorted"
Comment: Yes, this is effective for selecting multiple array items/keys.
Comment: The problem is that it leaves the index of the keys onsorted: [0] - a, [2] - b (the [1] is gone but the array still misses it)
Answer: If you know for definite that your array will contain only one element with that value, you can do
$key = array_search($del_val, $array);
if (false !== $key) {
    unset($array[$key]);
}

If, however, your value might occur more than once in your array, you could do this
$array = array_filter($array, function($e) use ($del_val) {
    return ($e !== $del_val);
});

Note: The second option only works for PHP5.3+ with Closures
Answer: $fields = array_flip($fields);
unset($fields['myvalue']);
$fields = array_flip($fields);

Comment: This only works when your array does not contain duplicate values other than the ones you're trying to remove.
Comment: @jberculo and sometimes that exactly what you need, in some cases it saves me doing a array unique on it aswel
Comment: apparently this is fastest as compared to selected solution, i did small benchmarking.
Comment: Maybe, but I would use functions specifically designed to do that, instead of being just a fortunate side effect of a function that is basically used and intended for something else. It would also make your code less transparent.
Comment: The message states "each value can only be there once"  this should work. It would have been nice if the poster had used the smae variable names though and added a little explenation
Comment: This solution was helpful for me because I had already made the array unique and did not care about the keys—only the values that had been returned by previous mutations.
Comment: **NOT RECOMMENDED** as other comment says.
Answer: With PHP 7.4 using arrow functions:
$messages = array_filter($messages, fn ($m) => $m != $del_val);

To keep it a non-associative array wrap it with array_values():
$messages = array_values(array_filter($messages, fn ($m) => $m != $del_val));

Comment: This is awesome.  Easy to understand, practical use of arrow functions which are new to me. I needed to remove part of an array of associative arrays based on a nested value which isn't really possible with any of the other answers.  I had resorted to using a `foreach()` loop, but this is much more concise.
Answer: The following answer using array_splice fails at 2 scenarios

If the searched value is not found, it removes the first element
It won't work with associative arrays.

Thus, it is not a good way to do. Not deleting my original answer because many others have also mentioned this array_splice as the best way. Therefore, updated my previous answer with reasons for it being the bad way to do.
Better if only removing 1 value from simple array
array_filter($array, fn($e) => $e !== $value)

Previous Original Answer Below
The Best way is array_splice
array_splice($array, array_search(58, $array ), 1);

Reason for Best is here at http://www.programmerinterview.com/index.php/php-questions/how-to-delete-an-element-from-an-array-in-php/
Comment: This will not work on associative arrays and arrays that have gaps in their keys, e.g. `[1, 2, 4 => 3]`.
Comment: It won't. Consider the array of my above comment; after I use your code to remove the value `3`, the array will be `[1, 2, 3]`; in other words, the value wasn't removed. To be clear, I'm not saying it fails in all scenarios, just this one.
Comment: array_splice is the best method,
unset will not adjust the array indexes after deleting
Comment: No sorry this will work. Please read the article I have provided link
Comment: Not a good solution. If you'll search for the value that doesn't exists: array_search will return "false", and array_splice will turn it into 0 and will remove first element in array.

$array = [3344, 4455, 5566];
array_splice($array, array_search(1122, $array), 1);
// as result $array = [4455, 5566]
Answer: Or simply, manual way:
foreach ($array as $key => $value){
    if ($value == $target_value) {
        unset($array[$key]);
    }
}

This is the safest of them because you have full control on your array
Comment: Using `array_splice()` instead of `unset()` will reorder the array indexes too, which could be better in this case.
Answer: function array_remove_by_value($array, $value)
{
    return array_values(array_diff($array, array($value)));
}

$array = array(312, 401, 1599, 3);

$newarray = array_remove_by_value($array, 401);

print_r($newarray);

Output
Array ( [0] => 312 [1] => 1599 [2] => 3 )
Comment: i'm not sure if this is faster since this solution involves multiple function calls.
Comment: Code-only answers are low-value on Stack Overflow.  Every answer should include an explanation of how it works or why you feel it is good advice versus other techniques.
Answer: you can do:
unset($messages[array_flip($messages)['401']]);

Explanation: Delete the element that has the key 401 after flipping the array.
Comment: not sure if this is correct, what if there are several elements with the value of `401`?
Comment: @saadlulu $messages array will not be flipped since array_flip() does not effect the original array, so the resulting array after applying the previous line will be the same except that the unwanted result will be removed.
Comment: You have to be very careful if you want to preserve the state. because all future code will have to have values instead of keys.
Comment: This will still preserve keys.
Answer: PHP 7.4 or above
function delArrValues(array $arr, array $remove) {
    return array_filter($arr, fn($e) => !in_array($e, $remove));
};

So, if you have the array as
$messages = [312, 401, 1599, 3];

and you want to remove both 3, 312 from the $messages array,
You'd do this
delArrValues($messages, [3, 312])

It would return
[401, 1599]

The best part is that you can filter multiple values easily, even there are multiple occurrences of the same value.
Comment: Note that an expanded form of the `array_filter` version could be used on older versions of php, such as:

`
  array_filter(
    $arr,
    function($arg) use ($black_list) {
      return !in_array($arg, $black_list);
    }
  );
`
Answer: The accepted answer converts the array to associative array, so, if you would like to keep it as a non-associative array with the accepted answer, you may have to use array_values too.
if(($key = array_search($del_val, $messages)) !== false) {
    unset($messages[$key]);
    $arr = array_values($messages);
}

The reference is linked here
Answer: To delete multiple values try this one:
while (($key = array_search($del_val, $messages)) !== false)
{
    unset($messages[$key]);
}

Comment: This will be less efficient than looping over the input one time (and there are multiple tools for doing this).  Imagine you are iterating an indexed array with 10 elements and you want to remove the elements at index 4 and 8.  This will iterate from 0 to 4, then unset element [4], then it will iterate 0 to 8, then unset element [8].  See how this technique will needlessly check [0], [1], [2], [3] more than once.  I would never use this technique for any reason and I recommend that all researchers take a wide birth from this answer. (this is the reason for my DV)
Answer: If you don't know its key it means it doesn't matter.
You could place the value as the key, it means it will instantly find the value. Better than using searching in all elements over and over again.
$messages=array();
$messages[312] = 312;
$messages[401] = 401;
$messages[1599] = 1599;
$messages[3] = 3;

unset($messages[3]); // no search needed

Comment: Only works for objects that can be converted to a string.
Comment: And no two values are the same. Which VERY often is not the case, although in the OP case, it seems to be.
Answer: Borrowed the logic of underscore.JS _.reject and created two functions (people prefer functions!!)
array_reject_value: This function is simply rejecting the value specified (also works for PHP4,5,7)
function array_reject_value(array &$arrayToFilter, $deleteValue) {
    $filteredArray = array();

    foreach ($arrayToFilter as $key => $value) {
        if ($value !== $deleteValue) {
            $filteredArray[] = $value;
        }
    }

    return $filteredArray;
}

array_reject: This function is simply rejecting the callable method (works for PHP >=5.3)
function array_reject(array &$arrayToFilter, callable $rejectCallback) {

    $filteredArray = array();

    foreach ($arrayToFilter as $key => $value) {
        if (!$rejectCallback($value, $key)) {
            $filteredArray[] = $value;
        }
    }

    return $filteredArray;
}

So in our current example we can use the above functions as follows:
$messages = [312, 401, 1599, 3, 6];
$messages = array_reject_value($messages, 401);

or even better: (as this give us a better syntax to use like the array_filter one)
$messages = [312, 401, 1599, 3, 6];
$messages = array_reject($messages, function ($value) {
    return $value === 401;
});

The above can be used for more complicated stuff like let's say we would like to remove all the values that are greater or equal to 401 we could simply do this:
$messages = [312, 401, 1599, 3, 6];
$greaterOrEqualThan = 401;
$messages = array_reject($messages, function ($value) use $greaterOrEqualThan {
    return $value >= $greaterOrEqualThan;
});

Comment: Isn't this reinventing filter? http://php.net/manual/en/function.array-filter.php
Comment: Yes indeed. As I am already saying at the post "or even better: (as this give us a better syntax to use like the array_filter one)". Sometimes you really just need to have the function reject as underscore and it is really just the opposite of the filter (and you need to get it with as less code as possible). This is what the functions are doing. This is a simple way to reject values.
Answer: A one-liner using the or operator:
($key = array_search($del_val, $messages)) !== false or unset($messages[$key]);

Answer: I know this is not efficient at all but is simple, intuitive and easy to read.
So if someone is looking for a not so fancy solution which can be extended to work with more values, or more specific conditions .. here is a simple code:
$result = array();
$del_value = 401;
//$del_values = array(... all the values you don`t wont);

foreach($arr as $key =>$value){
    if ($value !== $del_value){
        $result[$key] = $value;
    }

    //if(!in_array($value, $del_values)){
    //    $result[$key] = $value;
    //}

    //if($this->validete($value)){
    //      $result[$key] = $value;
    //}
}

return $result

Answer: Using array_filter and anonymous function:
$messages = array_filter($messages, function ($value) use ($del_val) {
    return $value != $del_val;
});

You can run a code example here: https://onlinephp.io/c/4f320
Answer: As per your requirement "each value can only be there for once" if you are just interested in keeping unique values in your array, then the array_unique() might be what you are looking for.
Input:
$input = array(4, "4", "3", 4, 3, "3");
$result = array_unique($input);
var_dump($result);

Result:
array(2) {
  [0] => int(4)
  [2] => string(1) "3"
}

Comment: This post IN NO WAY answers the OP's question.  This is the correct answer to a different question.  (this is the reason for my DV)
Comment: this answer is not related to the question
Answer: I think the simplest way would be to use a function with a foreach loop:
//This functions deletes the elements of an array $original that are equivalent to the value $del_val
//The function works by reference, which means that the actual array used as parameter will be modified.

function delete_value(&$original, $del_val)
{
    //make a copy of the original, to avoid problems of modifying an array that is being currently iterated through
    $copy = $original;
    foreach ($original as $key => $value)
    {
        //for each value evaluate if it is equivalent to the one to be deleted, and if it is capture its key name.
        if($del_val === $value) $del_key[] = $key;
    };
    //If there was a value found, delete all its instances
    if($del_key !== null)
    {
        foreach ($del_key as $dk_i)
        {
            unset($original[$dk_i]);
        };
        //optional reordering of the keys. WARNING: only use it with arrays with numeric indexes!
        /*
        $copy = $original;
        $original = array();
        foreach ($copy as $value) {
            $original[] = $value;
        };
        */
        //the value was found and deleted
        return true;
    };
    //The value was not found, nothing was deleted
    return false;
};

$original = array(0,1,2,3,4,5,6,7,4);
$del_val = 4;
var_dump($original);
delete_value($original, $del_val);
var_dump($original);

Output will be:
array(9) {
  [0]=>
  int(0)
  [1]=>
  int(1)
  [2]=>
  int(2)
  [3]=>
  int(3)
  [4]=>
  int(4)
  [5]=>
  int(5)
  [6]=>
  int(6)
  [7]=>
  int(7)
  [8]=>
  int(4)
}
array(7) {
  [0]=>
  int(0)
  [1]=>
  int(1)
  [2]=>
  int(2)
  [3]=>
  int(3)
  [5]=>
  int(5)
  [6]=>
  int(6)
  [7]=>
  int(7)
}

Comment: Simplest? Did you see, by chance, the accepted answer?
Answer: here is one simple but understandable solution:
$messagesFiltered = [];
foreach ($messages as $message) {
    if (401 != $message) {
        $messagesFiltered[] = $message;
    }
}
$messages = $messagesFiltered;

PHP array delete by value (not key)


FL Studio 12 automation chain

Question: Is it possible in FL Studio 12 create a chain of automation like so:

Parametric EQ2's knob is being controlled by some external LFO source
This knob controls another knob in the same plugin instance

or like so:

Parametric EQ2's knob is being controlled by some external LFO source
This knob controls another knob in different iVST/VST plugin like WaveSharper or something else
Answer: A year and a half late but here's what you can do (hoping it is indeed what you asked for):

Automate your first knob as usual.
Right-click the second knob that you want to have follow the same automation.
Select Link to controller.
Under the Internal controller section, in the drop down, find the automation you created for the first knob.
Uncheck Remove conflicts (or the first knob will be unlinked from its automation).
Accept.

Now both knobs are following the same automation.
If you wish to link a same knob to more than one automation in the same way:

Right-click your knob and Link to controller again
Another drop down made its appearance at the top of the dialog. It should say Link 1 or something similar. Select New Link.
Select another automation from the Internal controller drop down (and don't forget to uncheck Remove conflicts)

Hope that helps. :)
Also, useful piece of info in case you don't know: when 3rd-party VST knobs are right-clicked, they will show a contextual menu defined by the VST, not FL Studio's usual menu. In order to find the Create automation clip option:

Tweak the knob you wish to automate
Navigate to FL Studio's Tool menu (top-left of the screen)
Last tweaked > Create automation clip

This also works for Link to controller and any other option you'd expect to find in FL Studio's contextual menu.

FL Studio 12 automation chain


How to compute the nth number of a general Fibonacci sequence with matrix multiplication?

Question: If we want to compute the nth Fibonacci number we just power the matrix
$M =
\left[\begin{array}{cc}
1 & 1 \\
1 & 0
\end{array}\right]$
 $n$ times and we get $M =\left[
\begin{array}{cc}
F_{n+1} & F_n \\
F_n & F_{n-1}
\end{array}\right]$
But, How should be the elements arranged when I want to find the $n$th term of the fibonnaci series whose starting elements are $a$ and $b$?
Answer: If $a_{n} = a_{n-1} + a_{n-2}$, then
$$
{\begin{bmatrix}
  1 & 1 \\
  1 & 0 \\
\end{bmatrix}}^n
\begin{bmatrix}
  a_1 \\
  a_0 \\
\end{bmatrix} =
\begin{bmatrix}
a_{n+1} \\
a_n
\end{bmatrix}
$$
for any $a_0, a_1$.
Any linear recurrence relation can be solved using matrix exponentiation, e.g.,  $a_{n}=a_{n-1}-3a_{n-3}+5a_{n-5}-7$.
See this blog post: Recurrence relation and matrix exponentiation.
Answer: If you have a sequence, say $G_{-1} = a, G_0 = b$, and $G_{n+1} = G_{n} + G_{n-1}$, note that
$$\left[\begin{array}{cc}
1 & 1 \\
1 & 0
\end{array}\right]\cdot\left[\begin{array}{c} G_n \\ G_{n-1} \end{array}\right] = \left[\begin{array}{c} G_n + G_{n-1} \\ G_n \end{array}\right] = \left[\begin{array}{c} G_{n+1} \\ G_n \end{array}\right].$$
Then it isn't too hard to show that
$$\left[\begin{array}{cc}
1 & 1 \\
1 & 0
\end{array}\right]^n\cdot\left[\begin{array}{c} b \\ a \end{array}\right] = \left[\begin{array}{c} G_{n} \\ G_{n-1} \end{array}\right].$$
Answer: Just multiply your power matrix by the vector $[a,b]$ and you will get the $n+1$th and $n$th terms of your sequence as the resultant vector.


Delphis ZLib Interface not initialized

Question: When working with Delphi XE2 I have the following problem:
When I try to compress a response from IdHTTPServer that should be sent to a client, I am not able to do this. The IdCompressorZLib.CompressHTTPDeflate or IdCompressorZLib.CompressStream functions always stop with the error ZLib Error (-6). This means that Delphi does not find a library with the expected version. ZLIB_VERSION is set to 1.2.5 in my environment.
My question is what I have to do to get it working?
Comment: Why don't you use the `zlib` library that ships with Delphi? This avoids the need for an external DLL. The zlib objects are statically linked.
Comment: No, that's not what happened. Your code did not work. The `zlib` library works.
Comment: Hello,I tried it but it did not work.
Comment: The Lib for indy compression is linked statically as well. But it seems to be the wrong version. There are examples for IdHTTPServer and Indy compression on the web but not for system.zlib. I am not able to get it running.
Comment: Well, your mention of `ZLIB1.DLL` suggests dynamic linking.
Comment: there is a compiler directive in the indy stuff which is always defined: STATICLOAD_ZLIB. That lets me assume that the library is linked statically. The loadlibrary is never called.
Comment: OK, so I removed the references to DLLs that were confusing me. Now, which Indy are you using? Emba's version that came with XE2, or the latest Indy?
Comment: The indy version is 10.5.8.0. It came with delphi XE.
Comment: Thanks. I cannot help you any more I think. I'm sure you can use built in `zlib`, but since Indy offers zlib functionality I'd probably try to get that working.
Answer: OK, I've fired up XE2 and can reproduce what you report. It would seem that Embarcadero have blundered when building Indy for XE2. There is a mismatch between the zlib version of the linked objects, and the zlib version that is passed to the zlib initialization functions. Nothing you can do with what they shipped can work around that flaw.
Your options, as I see it:

Fix the version of Indy that was supplied with XE2. This will involve modifying the Indy source files and fixing the version mismatch. And then linking the modified Indy units to your application. Not impossible, but possibly a little awkward.
Use the latest version of Indy, obtained from the Indy project repo. You'll then have the latest and greatest Indy.
Use a different zlib library. For example the zlib library that ships with Delphi is known to work. I know you had trouble with this when I suggested it in a comment, but I for one have used it without trouble.
Use a different version of Delphi. Not a great option, but I'm including it for completeness.

Delphis ZLib Interface not initialized


'Dynamic' connection string for ms-access C#

Question: I have an access database connected to my code via a connection string as shown:
connection = new OleDbConnection(@"Provider=Microsoft.ACE.OLEDB.12.0;Data Source=C:\Users\Me\Documents\Visual Studio 2013\Projects\Computing Project\Database.accdb;
Persist Security Info=False;");

However I would like this app to be able to be installed on other devices, so I'm guessing the connection string has to be dynamic and change on each system. How would I use this in my code?
Comment: Reading the value from your config file instead of hard coding it?
Answer: Add an App.config to the solution with following content
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
    <startup>
        <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5.1" />
    </startup>
  <connectionStrings>
    <add name="MyCon" connectionString="Provider=Microsoft.ACE.OLEDB.12.0;Data Source=C:\Users\Me\Documents\Visual Studio 2013\Projects\Computing Project\Database.accdb; Persist Security Info=False;"/ >
  </connectionStrings>
</configuration>

Then in code,
connection = new OleDbConnection(ConfigurationManager.ConnectionStrings["MyCon"].ToString());

PS: ConfigurationManager class is in assembly System.Configuration.
So please add a reference of this assembly before using it.
Comment: I have added the System.Configuration reference but when I use this code it says that I have invalid arguments? I use the name of my connection string in place of yours and it still doesn't seem to work.
Comment: I've missed to convert it to string. Please check updated answer
Comment: It worked thank you! Where would be the best place to put the database (folder wise) for when it comes to building the solution?
Comment: You're very welcome. Could you please mark my answer as accepted. Create a folder named App_Data in solution and include the file in it.


POST form values over HTTPS

Question: I'm fairly unfamiliar with HTTPS, but I know it's secure, what I want to know is when a user logs in with details on a form, are the variables in that form (username, password) sent to the server encrypted?
I'm asking this, as I'm using a form to log people in, but I'm also hashing their passwords with MD5 together with a SALT for verification.
Also, is HTTPS secure enough to prevent any spyware running on the host from intercepting the login details?
Sorry for asking a few questions in this post, but thanks in advance for any answers.
Comment: MD5 is insecure.  Do not use it.
Comment: I see Joomla uses MD5 with SALT (as I'm doing), is this then ineffective? I also use multiple hashing, first hashing the (password) and then hashing the (password.salt). What other hashing do you recommend?
Comment: @SLaks why everyone is afraid of MD5, especially that SALT is involved in the encryption
Comment: I hope you're using cryptographically secure per-user random _byte sequences_ (not ASCII) as salt.  BTW, salt is not an acronym and should not be capitalized.
Answer:
I'm fairly unfamiliar with HTTPS, but I know it's secure, what I want to know is when a user logs in with details on a form, are the variables in that form (username, password) sent to the server encrypted?

The entirety of the HTTP request and response are encrypted.
The DNS look-up to convert the hostname to an IP address will, however, not be.

Also, is HTTPS secure enough to prevent any spyware running on the host from intercepting the login details?

No. HTTPS encrypts the communication between the client and the server. It cannot prevent software on the client from interfering with the request or reading the response. This includes the possibility of an attacker intercepting the request for the form and modifying it — so the form must be sent over SSL too.
Comment: @gawpertron — Wrong. If it sent over HTTPS then the query string will be encrypted.
Comment: The initial request url query params will not be encrypted
Answer: OK.  Let's break this question up a bit and cover a few things here.
First: you say that you know that HTTPS is "secure".  Let's qualify that a bit.
HTTPS is an encryption mechanism, and nothing more than that, so using HTTPS in itself does not guarantee "security" in any broader sense.  If you're using HTTPS, all you know, really, is that whatever information is sent from your visitor's browser to your server will be sent over an encrypted communication channel, such as to protect against Man-in-the-Middle Attacks.
While that is essential, using encryption/HTTPS in no way protects you from any other number of other potential vulnerabilities, including broken authentication mechanisms, SQL injections, Cross-Site Scripting (XSS), and a host of others.
If you're interesting in learning more about Information Security in General, I'd strongly recommend that you read Secrets and Lies by Bruce Schneier, who is a well-respected security authority.  The book is a bit old now, but the information it contains has aged very well, in my opinion.
Second: Just to be explicit, using HTTPS will in no way protect you from Spyware, etc.  Remember that HTTPS merely ensures encrypted communications, but can do nothing more than that.
Third: As SLaks has said, MD5 is probably not the best hashing algorithm to use anymore.  While I'm not an expert on cryptography by any means, I think you're still reasonably safe if you use SHA1 (plus a strong salt) instead.  To the best of my knowledge, MD5 has suffered some mathematical defeats over the last few years which has weakened its security.
If you're interested in learning the nitty-gritty details of web security, I'd also strongly recommend The Web Application Hacker's Handbook, which I consider to be an excellent primer on the subject.
I hope that's helpful.
Answer: All data sent to and from the server in an HTTPS request is encrypted.
This include the URL, headers, POST data, and response.
If your enemy has code running on either endpoint, he's already defeated you.
There is nothing you can do about it that he can't beat.
Comment: No; not at all.  You could offer free anti-virus software and hope that your users install it.
Comment: We'll assume the hosting server is secure, but is there any way then to protect on the client side?
Answer: HTTPs is a protocol used to prevent watching the data being sent between you and the server by ISPs or public WIFI hijackers and other cases, It may not prevent a spyware on your server to read it, To post data using SSL you only need to set the action attribute to a full https:// end url assuming you already installed an SSL certificate.
From Wikipedia:

Hypertext Transfer Protocol Secure
  (HTTPS) is a combination of the
  Hypertext Transfer Protocol with the
  SSL/TLS protocol to provide encrypted
  communication and secure
  identification of a network web
  server.

About the MD5, I believe that your combination of MD5 And SALT technique is fairly secure and it prevents hackers to easily find popular passwords if they gained access to your database.
Answer: HTTPS is certainly secure for traffic in both directions (assuming you keep the private key secure).  Spyware could compromise the private key and thus the security of HTTPS traffic to the host.
Answer: The purpose of HTTPS is used to maintain these three fundamental information security needs:

Confidentiality – Only the recipient can read the transmitted message that was meant for him/her.
Integrity – Recipient can detect whether the transmitted message got compromised.
Authenticity – Recipient can verify that the transmitted message is from the sender.

That's it. Note that this does only apply for the transmitted message. What is being sent and what happens with the data on the sender's and recipient's side is out of scope as HTTPS does only protect the transmission channel.
Particularly this means that it is possible that for example

the sender sends already malicious data over an HTTPS protected channel
the recipient receives sensible data over an HTTPS protected channel but there is spyware on the machine that can read the data.

So to answer your two questions:

[…] when a user logs in with details on a form, are the variables in that form (username, password) sent to the server encrypted?

Yes, if you use HTTPS for the transmission the transmitted data is encrypted by the client and only the server can decrypt it.

Also, is HTTPS secure enough to prevent any spyware running on the host from intercepting the login details?

No, as already said, HTTPS does only protect the data transmission from the sender to the recipient. Anything beyond that is out of scope.

POST form values over HTTPS


Cant find database table with node stickiness

Question: I watched into Drupal 7 database, but i cannot find a table where nodes have stored their "sticky" value. Any ideas?
Answer: You need to look harder!
The node table has a sticky column, the data is stored there.
Comment: You were right! i forgot that database has a pagination.. my bad.. Thanks for your effort anyway!
Answer: You can find field in node table as mention @clive
Comment: Yeah.. i see.. i oversaw an pagination. Thanks for your effort!


What is the mean queue delay in a M/M/1 queue with $\lambda = \mu$?

Question: I'm trying to solve a problem where all arriving items (arrival exponential $\lambda = 1/5$) are divided into into groups, those who are served within 5 units of time and those who have their service time $>5$. The service is also exponential $\mu = 1/5$
Should I use truncated exponential?
Answer: I'm going to assume you meant for us to assume exponentially-distributed inter-arrival time distributions. Otherwise you will need to provide us with more information.
Under that assumption, both arrival distributions are:
$$T_{\text{arrival}} \sim \text{Exponential} \left( \frac{1}{5} \right)$$
And it appears that you are telling us that the service time distributions are the same for both classes of item:
$$T_{\text{service}} \sim \text{Exponential} \left( \frac{1}{5} \right)$$
The queueing delay is the time a job waits in a queue until an item can be served. This is also called the waiting time, and it sounds like you are interested in the expected wait time conditioned on whether the item was in one of these two groups. You have not told us how many servers there are, so the problem cannot be uniquely answered. Let us suppose that there is one server for the sake of example, and you can change the code below to obtain different answers if you had some other number in mind.
We can readily simulate this using Ciw. Let's simulate for $10^4$ items.
# Import required libraries
import ciw
import pandas as pd

# Set a seed to fix the pseudorandom result
ciw.seed(2018)

# Instantiate a network object accord to specification
network = ciw.create_network(
    arrival_distributions = [ciw.dists.Exponential(1/5)],
    service_distributions = [ciw.dists.Exponential(1/5)],
    number_of_servers = [1]
    )

# Instantiate a simulation object which will run the simulation
simulation = ciw.Simulation(network)

# Simulate until 10^4 customers have sojourned
simulation.simulate_until_max_customers(10000)

# Collect and process simulation results
records = pd.DataFrame(simulation.get_all_records())
records['group'] = (records.service_start_date - records.arrival_date) < 5
records['group'] = records['group'].apply(lambda x: 'lower' if x else 'upper')

# Print summary of results as Markdown table
print(
    (records
     .groupby('group')['waiting_time']
     .describe()
     .to_markdown())
    )

group
count
mean
std
min
25%
50%
75%
max

lower
252
1.26813
1.64162
0
0
0.0176671
2.49742
4.9942

upper
9748
241.778
159.389
5.0305
100.27
225.795
349.237
622.003

You can see that the average for those in the lower group is about 1.26813. However, I would not trust the mean for the upper group to be 241.778. Why? Because I don't think it is stationary. Take a peek at the plot of the arrival date vs waiting time.
records.plot(x='arrival_date', y='waiting_time'); plt.show()

Because $\rho = \frac{\lambda}{\mu} = 1 \not < 1$, the system is unstable. These statistics (especially for the upper group) will depend on how long you simulate for.
Comment: The "1" in M/M/1 is the number of servers.  The system is indeed not stationary, and the expected wait time is infinite, as is the expected length of the wait queue.  There is no stationary distribution for either wait time or length of queue, but the limit of the probability that the wait time $< T$ for any $T$ as $\lambda/\mu \to 1$ from below is zero.


How to get an overall p-value for an independent categorical variable using generalized estimating equations (geeglm) in R

Question: I would like to know if there is a way to get an overall p-value for an independent categorical variable using generalized estimating equations in R. When I run the analysis, the output provides p-values for each level of the categorical variable, instead of an overall p-value for the variable itself.
One example of an output is this:
install.packages("geepack", dependencies=TRUE)
library(geepack
#some code using geeglm with binomial errors
# Results

Call:
geeglm(formula = modality ~ factor(smoking_status), family = "binomial",
    data = airleak_cleaned_included, id = as.factor(mrn))

 Coefficients:
                        Estimate Std.err  Wald Pr(>|W|)
(Intercept)                0.875   0.266 10.82    0.001 **
factor(smoking_status)1   -0.359   0.338  1.13    0.287
factor(smoking_status)2   -1.099   0.722  2.32    0.128
---
Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1

Correlation structure = independence
Estimated Scale Parameters:

            Estimate Std.err
(Intercept)        1  0.0597
Number of clusters:   176  Maximum cluster size: 1

Comment: Edit to SO standards. I think this is really a stats question.
Comment: Yes, but its easier to do using score tests rather than Wald tests.  In principle: fit an intercept-only model and save the results in, say, `fit0`.  Then fit your model above above and save the results in, say, `fit1`.  Then call `anova(fit0, fit1)`.  For more details, please ask on StackExchange.  I am voting for migration.
Answer:   I'm posting an "answer", but I don't really want it considered as such because I don't have much statistical theory behind it.  With Thomas Lumley's endorsement of this as acceptable practice, I'll consider it an answer.  I can show the mechanics of getting a result using R. I  seconded Limey's vote to migrate to stats.stackexchange.com after I searched that site for an answer to the general question of "how to do a principled model comparison" on GEE modeling results to get "overall significance" estimates from those GEEs. I didn't find what I considered to be a satisfying answer on either SO or CV.com.
This code  installs and loads the R library 'geepack' and then builds 2 models (with one that sets the RHS of a formula to 1 to build a "Null model") based on the example code in ?geeglm and then runs anova on the two models. That package does have an anova.geeglm function which I take to imply that the authors think this is valid in at least some situations.
install.packages('geepack')
library(geepack)
data(dietox)
dietox$Cu     <- as.factor(dietox$Cu)
mf <- formula(Weight ~ Cu * (Time + I(Time^2) + I(Time^3)))
gee1 <- geeglm(mf, data=dietox, id=Pig, family=poisson("identity"), corstr="ar1")
# warnings noted
gee1
coef(gee1)
vcov(gee1)
summary(gee1)
coef(summary(gee1))

mf2 <- formula(Weight ~ 1)
gee2 <- geeglm(mf2, data=dietox, id=Pig, family=poisson("identity"), corstr="ar1")
# more warnings

methods("anova") # to get available class-specific function names
 [1] anova.coxph*       anova.coxphlist*   anova.geeglm*      anova.glm*         anova.glmlist*     anova.glmmPQL*
 [7] anova.lm*          anova.lmlist*      anova.loess*       anova.loglm*       anova.mlm*         anova.negbin*
[13] anova.nls*         anova.polr*        anova.survreg*     anova.survreglist*
see '?methods' for accessing help and source code

anova(gee1,gee2)
#---------------
Analysis of 'Wald statistic' Table

Model 1 Weight ~ Cu * (Time + I(Time^2) + I(Time^3))
Model 2 Weight ~ 1
  Df   X2 P(>|Chi|)
1 11 9327    <2e-16 ***
---
Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1

If this were "regular" regression, I would have confidence that this was a valid approach to model comparison and that a X^2 difference of 9327 between nested models differing by 11 degrees of freedom pointed to a high "statistical significance" and a corresponding low p-value. However, I'm being appropriately modest because this is a statistical area about which I have no experience.
Comment: Yes, that's the right idea.  This isn't an anova in the traditional sense, because it's not based on a likelihood, but it does the tests that the original question wanted. In principle a score test might be easier because you don't need to fit the more-complex model but in practice it actually isn't easier and fitting the model is not a problem. The warnings are because the outcome variable isn't integer, which a Poisson variable would be; you can use `quasipoisson` to silence them.
Comment: @ThomasLumley : Thanks, Thomas. I wasn't familiar with the expression `Analysis of 'Wald statistic' Table` but I guess its being done with  inference based on the usual difference in chisquare-distributed  ( X^2) statistic with the difference in adjusted df.
Comment: No, it's *not* being done with the usual difference in chisquared statistics, which doesn't work in this context. It's based on $(\hat\beta-\beta_0)^TV^{-1}(\hat\beta-\beta_0)$ for the subspace of $\beta$ that is in the larger model but not the smaller one.  It doesn't have the nice property of traditional anova that the test statistics for A vs B and B vs C add to give the statistic for A vs C.
Comment: @ThomasLumley So those beta-hats are vectors and V^-1 is the full variance-covariance matrix? Shouldn't the the displayed results say something along those lines?
Comment: Not the full covariance matrix, the covariance matrix for the subset being tested. That's the coded message of "Wald Statistic" rather than likelihood ratio


error: invalid suffix "x" on floating constant

Question: #include <stdio.h>
#include <conio.h>
#include <math.h>
#define ESP 0.0001
#define F(x) x^3-2.5x^2-1.8x+2.356
void main()
{
  float x0,x1,x2,f1,f2,f0;
  int count=0;

  do
  {
  printf("\nEnter the value of x0: ");
  scanf("%f",&x0);
  }while(F(x0) > 0);
  do
  {
  printf("\nEnter the value of x1: ");
  scanf("%f",&x1);
  }while(F(x1) < 0);
  printf("\n__________________________________________________________\n");
  printf("\n    x0\t       x1\t x2\t   f0\t   f1\t   f2");
  printf("\n__________________________________________________________\n");
  do
  {
  f0=F(x0);
  f1=F(x1);
  x2=x0-((f0*(x1-x0))/(f1-f0));
  f2=F(x2);
  printf("\n%f %f %f %f %f %f",x0,x1,x2,f0,f1,f2);
  if(f0*f2<0)
   {
    x1=x2;
   }
   else
   {
    x0 = x2;
   }
  }while(fabs(f2)>ESP);
printf("\n__________________________________________________________\n");
printf("\n\nApp.root = %f",x2);
getch();
}

The program can't seem to read the #define F(x) x^3-2.5x^2-1.8x+2.356 as function but when I use #define F(x) 3*(x) - 1 - cos(x) there's no error.
I tried #define F(x) (x)^3-2.5(x)^2-1.8(x)+2.356, no luck.
Comment: `^` is the XOR operator. Also `2.5x^2` --> `2.5*x*x`
Comment: Use: `#define F(x) ((x)*(x)*(x) - 2.5*(x)*(x) - 1.8*(x) + 2.356)`. Note the use of paranthesis they are important as macros are just textual substitution.
Comment: what is ^ in your opinion?
Comment: and there*s no "implicit `*`".
Comment: ...such as `1.8x`
Comment: And, the entire expression (when corrected) should be parenthesised.
Comment: ;) real mathematicians cannot dev ;)
Answer:
F(x) x^3-2.5x^2-1.8x+2.356

^ is not the power operator in C use pow(), powf() function (but in this case there is no need of it)
2.5x has to be 2.5 * x - buy a book about C
do not #define functions make them "real"functions
Do not use double literals in float expressions

float F(float x)
{
  return x * x * x + 2.5f * x * x + 1.8f * x + 2.356f;
}

Comment: As much as I want to use that code I don't know where to place it.


Linux-Vserver: How to do upgrade Debian 5.0 to 6.0 on vservers and main machine?

Question: I have server with debian lenny. I installed vserver on this server a few years ago. Summary I have 5 guest of vservers and main system, now. Each guest is debian lenny.
Now, I'm wanting upgrade from lenny to squeezy on this servers (each Vservers and main machine).
Do you do it? I should upgrade as usually system ? First I should upgrade every vserver next main machines and I have to do reset all machines and vservers?
Please, advise me how to do it ?
Comment: Setup a test environment similar to your production setup, and try upgrading and see what happens?
Comment: We don't have a second machine where I can build debian with vservers. When I upgrade one vserver (only) I didn't started vserver. I cannot try upgrade only main machine because this can have 'epic fail'.
Answer: First of all make sure your kernel is 2.6.32. If it is not, it happened to me that auto-upgrade failed for some reason  (Because you are running a BPO kernel for example). In this case, depending on your architecture :
aptitude install linux-image-2.6-vserver-amd64

Given that the above kernel is used, you may proceed with the system upgrade. In similar situations i preffered to upgrade VMs first and then the host itself.
For the VMs the procedure would be:

Update the /etc/apt/sources.list for squeeze
Do the APT update and download the packages (especially when doing this from the internet, assuming there is no local repository mirror):
sudo apt-get clean && sudo aptitude update
sudo aptitude full-upgrade --download-only
Make sure that you install the appropriate driver packages for your hardware. It would be unpleasant to find yourself cut off from your remote server :)
Example: sudo aptitude install firmware-linux-nonfree
Do the safe upgrade for a few times until there is nothing left:
sudo aptitude safe-upgrade
Finally do a full upgrade:
sudo aptitude full-upgrade

For the host of your virtual machines there will be an additional step in updating GRUB to GRUB2. You can check if your bootloader was installed properly by running:
update-grub
If you do not see any errors, it is most likely safe to reboot.
If you get ANY error message about missing drivers, DO NOT REBOOT. Install necessary drivers before rebooting.
Depending on your actual environment and setup the above steps might differ a little, but these should give you a general idea.
Answer: I tried upgrade both on host of linux-vservers and linux-vservers guest - and i didn't havent any major problems.
Minor problems are:
 - lack of drivers/bad drivers on linux vserver host - sometimes they need to upgrade independly (network cards - r8168, e1000, dahdi drivers...)
 - some applications on squeeze needs newer kernel than lenny - so there were problems when i upgraded only guest, but not hosts (but it was rare situation)
In most situations - it was enough  to apt-get dist-upgrade on host, and then - one by one - dist-upgrade of guests.
If you're using vhashify feature - remember that dist-upgrade on one vserver often destroy unification - you must reinvoke it to spare place there after upgrading guests.


How should I organize files in VCS?

Question: I'm making a website and making multiple design prototypes. I want to keep all of them for future reference.

Is this a suitable place to use branches, or should I just put them in folders?
How should I manage external dependencies (e.g. jQuery), should I include a minified version for every design or keep one for the whole project or just link to an online version?
Answer: Branches are fine if:

you want to compare the differences of the same file across several variation of your website
develop in parallel said variations, in isolation (See "When should you branch?").

That won't prevent you top deploy those in different directories (you simply checkout each branch in different folder on your web server)
Any common part (like some JQuery script) should be in a sub-directory which is versioned in its own repo and referenced by your main web repo as a submodule.

How should I organize files in VCS?


Prove that $X_n \sim N(0,\frac{1}{n})$ converges in probability to 0

Question: Problem
Prove that $X_n \sim N(0,\frac{1}{n})$ converges in probability to 0.
Discussion
There a problems similar to this question, but I want to ask specifically about the convergence of an integral that arises in the solution.
Attempt
Let $\epsilon>0$. To show $X_n \overset{p}{\to} 0$, we must show $P(|X_n| > \epsilon) \to 0$.
$$
\begin{align}
P(|X_n|>\epsilon)
&= P(X_n>\epsilon) + P(X_n < -\epsilon)\\
&= P(Z>\epsilon\sqrt{n}) + P(X_n<-\epsilon\sqrt{n})
\end{align}
$$
where $Z$ is the standard normal distribution. Thus we want to show
$$P(|X_n|>\epsilon)=\int_{\epsilon\sqrt{n}}^\infty\frac{1}{\sqrt{2\pi}}e^{-\frac{1}{2}x^2}\text{dx}
+
\int_{-\infty}^{-\epsilon\sqrt{n}}\frac{1}{\sqrt{2\pi}}e^{-\frac{1}{2}x^2}\text{dx}\to 0$$
I understanding intuitively that these integrals should converge to zero, but how can I show rigorously that they go to zero?
Answer: Your integrals contain spurious instances of $\sqrt n$. You are evaluating $P(|Z|>\epsilon\sqrt n)$ where $Z$ is standard normal, so the integrand should not involve $\sqrt n$. Anyhow, you can prove $P(|Z|>\epsilon\sqrt n)\to0$ rigorously using Markov's inequality.
Answer: $$E[X_n]=0$$
$$\lim_{n \to \infty}\mathrm{Var}[X_n]=0$$
This is a necessary and sufficient condition for
$$X_n\xrightarrow{L^2}0$$
Convergence in $L^2$ implies convergence in probability
Answer: You can use the tail bound for a standard normal random variable:
$$
\int_x^\infty \exp(-y^2/2)\,dy \le x^{-1}\exp(-x^2/2),
$$
which can be proved changing variables $y = x + z$ and using $\exp(-z^2/2) \le 1$.
Comment: I am selecting this as my answer because it directly shows how to work with the integral, which is what I was specifically asking about. The other answers also offer great solutions.


Como fazer um background cover numa div separada?

Question: Estou fazendo um site com com menu lateral. 30% da tela é o menu e o restante é o conteúdo.
Na div do conteúdo, quero colocar uma imagem de fundo, utilizando o método COVER. Utilizei o primeiro:
https://css-tricks.com/examples/FullPageBackgroundImage/css-1.php
Porém, este método funciona perfeitamente quando a imagem ocupa todo o background. Como no meu exemplo eu quero que o mesmo ocupe exatos 70% da largura, ele "come" os cantos da imagem.
Como posso resolver isso?
HTML:

 ....conteudo.....

CSS:
.bg {
       min-height: 100%;
       min-width: 1024px;

       width: 100%;
       height: auto;

       position: fixed;
       top: 0;
       float: right;
}

 @media screen and (max-width: 1024px){
            .bg {
                left: 50%;
                margin-left: -512px;
}
}

Comment: Deixa eu ver se entendi, você deseja aplicar um bg na `div` do conteúdo, mas a `div#direita` já possui um bg, como um elemento `img`, é isso? Você não poderia aplicar esse background com css, sem utilizar a tag `img`?
Answer: Veja se isso é o que queria:

*{
   padding: 0;
   margin: 0;
   border: 0;
}
body, html{
  height: 100%;
}
#esquerda{
  width: 30%;
  height: 500px;
  background: url('https://css-tricks.com/examples/FullPageBackgroundImage/images/bg.jpg') no-repeat fixed;
  background-size: cover;
  background-position: center;
  float: left;
  clear: left;
}
#direita{
  width: 70%;
  height: 500px;
  background: url('http://shmector.com/_ph/17/990955453.png') no-repeat;
  background-size: cover;
  background-position: center;
  float: right;
  clear: right;
}

As duas divs possuem um bg com o método background-size: cover, ao invés de usar a tag img. Apenas o da div do conteúdo é fixo. O resto está de acordo com a definições da pergunta.
Imagem exemplo
Answer: Em vez de colocar uma tag  dentro da #direita, experimente aplicar o background pelo CSS.

#direita {
  background-image = url(fundo.jpg);
  background-size = cover;
  background-repeat = no-repeat;
}
Answer: Acredito que isso atenda sua necessidade:

.general { height: 800px; background: url('https://css-tricks.com/examples/FullPageBackgroundImage/images/bg.jpg');
background-position: right top;
background-size: 70%;
background-repeat: no-repeat;
}

Exemplo: https://jsfiddle.net/nux9199j/
Answer: Se eu entendi sua pergunta, para que a imagem encaixe cobrindo todo o fundo da div do conteúdo, coloque a propriedade background-size com esse valor. background-size:100% 100%.


J2ME LWUIT TabbedPane: How to change the tabbedPane Backgroung color and font color?

Question: I am new to lwuit. I have to change the tab background color and font color. I used
Tabbedpannel tabpannel = new Tabbedpannel();
style tabcolor =tabpannel.setBgcolor(111);

but the color of the tab is not changing...
Any one can help me..?
Thanks in advance...
Nimmy..
Answer: try tabpannel.getStyle().setBgColor(111)
Comment: TabbedPan id deprecated , use `Tabs` class, and use `Tabs tab = new Tabs(); tabs.getTabsContainer().getStyle().setBgColor(111);` for font color- use `setFgcolor()` method. use int 16711680 for test its red