Log4View UDP Message Structure

Question: I'm trying to send from various applications logs to Log4View by UDP (port 878), but i can't find any information of the message format on the web.
I've tried to send a simple string but it won't work at all.
Is there any information about it? I know that it is very simple task in C# with log4net, but the web is lack of information on other platforms.
Answer: To send log messages to Log4View via UDP, you have to use the xml format.
You can find more in our documentation about how to use the xml format:
http://www.log4view.com/fileadmin/user_upload/Log4ViewHelp/XML_Layout.html
Yours sincerely
Philipp Lauchner
PROSA GmbH
Development & Support
Comment: don't advertise you company in comments or answers, this can result in marking post as spam...

Log4View UDP Message Structure


Como retornar mais de uma coluna da mesma tabela?

Question: Com esta SQL eu consigo no meu banco de dados selecionar e agrupar produtos por variações que seriam neste caso diferentes atributos para o mesmo produto.
Assim, ao gerar a view do produto, eu tenho um dropdown no produto com todos os atributos podendo o cliente escolher num maior número de possibilidades para o mesmo produto, por exemplo um carro que tem várias cores.
Eis a SQL:
$BuscaProdutosAtivos = $pdo->prepare("SELECT tbl_produtos.*, tbl_categorias.*,
                                      GROUP_CONCAT(tbl_variacoes.valor) AS Variacoes FROM tbl_variacoes
                                      INNER JOIN tbl_produtos ON tbl_produtos.id = tbl_variacoes.cod_prod
                                      INNER JOIN tbl_categorias ON tbl_produtos.prod_categoria = tbl_categorias.cat_id
                                      GROUP BY (tbl_produtos.id)");

Com esta SQL eu retorno da tbl_variacoes a coluna valor. Eu gostaria de retornar valor, dimensao, quantidade pois estas três informações serão concatenadas dentro do dropdown formando uma variação. Como posso fazer isso usando esta SQL?
Eu imaginei que se pudesse usar diversos GROUP_CONCAT mas pesquisando em alguns lugares vi que não deve ser feito dessa forma.
Comment: Cada vez que você usa um `GROUP_CONCAT` para [algo que precisa quebrar depois](http://pt.stackoverflow.com/questions/41987/como-transformar-uma-string-em-um-select-com-php), 100 pessoas morrem de Ebola na África.
Comment: Falando sério agora, pode ser o caso de fazer queries separadas para pegar essas "variações". Para responder mais precisamente eu precisaria ver um exemplo do que você quer colocar no tal dropdown.
Comment: Ou simplesmente concatenar essas coisas no PHP, não no MySQL. Não está dando pra entender bem a pergunta.
Answer: Não entendi realmente o que você queria retornar, mas segue dois exemplos:
SELECT tbl_produtos.*, tbl_categorias.*,
tbl_variacoes.valor || tbl_variacoes.dimensao || tbl_variacoes.quantidade AS Variacoes

FROM tbl_variacoes

INNER JOIN tbl_produtos
ON tbl_produtos.id = tbl_variacoes.cod_prod

INNER JOIN tbl_categorias
ON tbl_produtos.prod_categoria = tbl_categorias.cat_id

Ou
SELECT tbl_produtos.*, tbl_categorias.*,
tbl_variacoes.valor, tbl_variacoes.dimensao, tbl_variacoes.quantidade

FROM tbl_variacoes

INNER JOIN tbl_produtos
ON tbl_produtos.id = tbl_variacoes.cod_prod

INNER JOIN tbl_categorias
ON tbl_produtos.prod_categoria = tbl_categorias.cat_id


Checking if string contains all letters from a Character arrayList

Question: I am trying to check if a certain String from a String arrayList contains all Characters from a Character arrayList.
This is what I am trying so far:
for (int wordNum = 0; wordNum < wordList.toArray().length; wordNum++){

                if (wordList.get(wordNum).contains((CharSequence) letters))
                {...}

The error comes from this line:
if (wordList.get(wordNum).contains((CharSequence) letters))

If anyone has any suggestions of how to fix this I appreciate it!
Answer: While there might be a better solution, the easiest way is to test for the occurrence of each character in the string separately.
for (int wordNum = 0; wordNum < wordList.toArray().length; wordNum++){
    boolean allChars = true;
    for(Character c : yellowLetters){
        if(!wordList.get(wordNum).contains(Character.toString(c))){
            allChars = false;
            break;
        }
    }
    if(allChars){
        ....
    }
}

Answer: yellowLetters is an ArrayList<Character> but you're trying to cast it with (CharSequence) yellowLetters.
Delete yellowLetters altogether - it's just the distinct letters of guessWord.
The simple way to know if a String contains all letters in guessWord is just:
if (guessWord.replaceAll("[" + word + "]", "").isEmpty())

This works by turning the word into a regex character class and deleting any matches from guessWord.
Answer: You cannot cast a List<Character> to CharSequence. An option would convert  wordList.get(wordNum)to a List and compare both Lists :
for (int wordNum = 0; wordNum < wordList.toArray().length; wordNum++){
          List<Character> wordChars = word
                .chars()
                .mapToObj(e -> (char)e)
                .collect(Collectors.toList());
          if (wordChars.containsAll(yellowLetters))
          {...}


$(\mathbb{R}^{3},\times)$ is a Lie algebra that does not have Lie subalgebras of dimension 2.

Question: Could anyone give me a suggestion to start solving this problem?
Proof that $(\mathbb{R}^{3},\times)$ is a Lie algebra that does not have Lie subalgebras of dimension 2.
Comment: addendum: $\times$ denotes the usual cross product
Answer: Given any two linearly independent vectors in $\mathbb{R}^3$, their cross product will be perpendicular to the plane that they generate. In particular, no $2$-dimensional subspace can be closed under the Lie bracket.
Answer: Just find a basis $(x,y,z)$ for the cross product algebra, which is the $3$-dimensional Lie algebra $\mathfrak{so}(3)$, e.g.,
with brackets
$$
[x,y]=z,\; [y,z]=x,\; [z,x]=y,
$$
see this question. Now it is obvious that there is no $2$-dimensional subalgebra - see also this duplicate.


css not updating even after deleting cache/hard refresh

Question: im trying to add an id to my contact section element in my page ! but it just doesn't update !
adding anything new to my css won't work, but modifying selectors that are already loaded in the page is possible !
The selector is written with background-color property and other things, but when i inspect the element (developer tool) , i can't see the selector and properties i already defined. But other old selectors are shown perfectly...
here's a picture:
here's the dev-tool screenshot
What i tried :
I tried to use a class instead of ID, didn't work.
Tried to change version by adding ?v.1 ?v.2  and ?version=15 ... every time i modify, didn't work.
Tried every type of cache reload and delete, didn't work.
Tried to open the page in the browser manually (open htdocs/myproject/index.html nd double click it), not by the local server (xampp localhost), didn't work.
Tried all available web browsers, doesn't work.
Tried to open the project in another pc , it doesn't work too.
Th
HERE'S THE WHOLE HTML:
<!DOCTYPE html>

        <meta charset="utf-8">
        <meta name="viewport" content="width=device-width,initial-scale=1">
        <link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.5.0/css/bootstrap.min.css" integrity="sha384-9aIt2nRpC12Uk9gS9baDl411NQApFmC26EwAOH8WgZl5MYYxFfc+NcPb1dKGj7Sk" crossorigin="anonymous">

        <link href="https://fonts.googleapis.com/css2?family=Roboto:ital,wght@0,300;0,400;1,300;1,400;1,500&display=swap" rel="stylesheet">
        <link rel="stylesheet" type="text/css" href="css/styles1.css">

        <title>portfolio</title>

                        <button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarNav" aria-controls="navbarNav" aria-expanded="false" aria-label="Toggle navigation">

                        </button>

                              Home (current)

                                portfolio

                                  Photography
                                  Wedding
                                  Landscapes
                                  Product photography

                              About me

                              Booking

                                Contact

badr kahouaji

hire a professional photographer

                        <button class="btn btn-primary">About me</button>
                        <button class="btn btn-primary">Bookings</button>

My story

Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting

Portfolio

Shoreline

Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled

Shoreline

Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled

tessttt

Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled

test

Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled

test

4923 Market Street. Orlando FL

HERE'S THE WHOLE CSS:
*{
    margin:0;
    padding:0;
    font-family: 'Roboto', sans-serif;
}
.bluedivider{
        height:3px;
    width:100px;
    background-color: #191970;
    margin-bottom: 35px;
}
.pfrows{
    margin:3% 0 3% 0;
}

/* navbar */
nav{
    align-items: center;
    justify-content: center;
}
nav li{
    padding:5%;
}
nav a{
    white-space: nowrap;
    text-transform: uppercase;
    color : #003bae;
    font-size:20px;
    font-weight: bold;
}
.dropdown-menu{
    top:60%!important;
    padding: 4px;

}
.dropdown-item{
    font-size:16px;
    font-weight: bold;
}

/* firstbg */

#firstbg{
    background-image: url("../img/home/LSCAPE1.jpeg")  ;
    -webkit-background-size: cover;
    background-size:cover;
    /* background-attachment: fixed; */
    background-position: center;
    background-repeat: no-repeat;
    text-align: center;
}
#firstbg h2{
    padding-top:14%;
    font-size: 700%;
    text-transform: uppercase;
    color : #fff;
}
#firstbg h4{
    padding-bottom: 5%;
    text-transform: uppercase;
    font-size: 25px;
    font-weight: bold;
    color : #fff;
}
.buttons button{
    margin:4% 1% 4% 1%;
    font-size: 22px;
    text-transform: uppercase;
    background-color: #3d59ab;
    border:3px solid #3d59ab;
    border-radius: 15px;
    padding:12px;
    transition: all 0.2s ease-in;
}
.buttons button:hover{
    background-color: #191970;
    border:3px solid #191970;
}

/* story */
#story{
    background-color :#0c0411;
}
.reddivider{
    height:3px;
    width:100px;
    background-color: #a20d5b;
    margin-bottom: 15px;
}
.mystory{
    padding:15% 0% 15% 0%;;
    text-align: left;
}
.mystory h2{
    font-size: 60px;
    text-transform: uppercase;
    color : #fff;
}
.mystory p{
    color :#fff;
    font-size: 22px;
    font-weight: 500;
}

/* PORTFOLIO */

#portfolio{
    padding:3%;
    text-align: center;
    margin-top: 50px;

}
#portfolio h2{
    font-size:35px;
    font-weight: bold;
    margin-bottom: 15px;
    letter-spacing: .0625em;
}

.img{
    padding-right: 0px;
    padding-left: 0px;
}
.text{
    margin-top: 150px;
    margin-bottom: auto;
}
.textleft{
    border-right: .5rem solid #64a19d;
}
.textright{
    border-left: .5rem solid #64a19d;
}
.pfrows{
    background-color: rgba(61,89,171,.6);

}

.text h3{
    font-size: 1.5rem;
    font-weight: 500;
    color : #fff;
    line-height: 1.2;
    letter-spacing: .0625em;
}
.text p{
    color:rgba(0,0,0,.5)!important
}
.texttwo{
    width: 100%;
    padding: 1%;
    margin-left: auto;
    margin-right: auto;
    margin-top:130px;
};

#contacts{
    background-color : #000;
}

----------

Does anyone have an idea why this is happening ??
Comment: Check that you're editing the right CSS file and that it's actually being included in your HTML. You want to be editing `css/styles1.css` which is relative to where your HTML is being served from.
Answer: I checked your code. It works for me. I include both html file and css in same folder. So I change the path as href="styles1.css"in html file.
Answer: I think I know what your problem is.
I tried the code myself and watched the same behavior. You want the background to be black and it just won't.
Well, I think the problem is there's a more important CSS rule blocking your:
#contacts{ background-color: #000; }

rule.
I found out that if you move that rule to the top of the CSS file, you'll get your black background.
I suggest you check it out, and find out what rule is blocking your black #contacts section background.

In the picture I show you, I moved the #contacts rule up (to line 7), so now it's the second rule and it just works. The background is black.
Of course, now you should set your font color to a brighter one ! :)


how to redirect Wordpress 404 page through function()

Question: I want to change a role in my wordpress plugin.
<code>            if ( is_admin() && ! is_user_logged_in() && ! defined( 'DOING_AJAX' ) && $pagenow !== 'admin-post.php' ) {
            wp_die( __( 'This has been disabled', 'wp-hide-login' ), 403 );
        }

        $request = parse_url( $_SERVER['REQUEST_URI'] );
</code>
When my plugin get the action, Wordpress shows "This has been disabled" under WP default (admin-post.php) page.
But i need when my function get assign it's redirect to 404 page.
As like as  "This has been disabled" > http://www.example.com/404
Comment: Do you need [this](https://wordpress.stackexchange.com/a/27124/113464)?
Answer: <code><?php
 if ( is_admin() && ! is_user_logged_in() && ! defined( 'DOING_AJAX' ) && $pagenow !== 'admin-post.php' )
      {
             global $wp_query;
            $wp_query->set_404();
            status_header( 404 );
            get_template_part( 404 ); exit();
        }
</code>
?>


Remove a combination of Number and . from a string in Excel

Question: I have the input "Nokia S40 Browser 2.2.0"  from this i want to remove version number. The output should be "Nokia S40 Browser". In other words i want to remove 2.2.0 from my input. How can I do that?
Answer: If the version number is always the last part of the text then you can use
<code>=TRIM(RIGHT(SUBSTITUTE(A1," ",REPT(" ",100)),100))
</code>
To get the last part and
<code>=SUBSTITUTE(A1,TRIM(RIGHT(SUBSTITUTE(A1," ",REPT(" ",100)),100)),"")
</code>
To remove the last part of the text.

Or you could use a RegEx to remove the version numbers
<code>Function remomveVers(Myrange As Range) As String
    'Dim regEx As New regEx
    Set regEx = CreateObject("VBScript.RegExp")
    Dim strPattern As String
    Dim strInput As String
    Dim strReplace As String
    Dim strOutput As String

    strPattern = "([0-9]{1,2}[.][0-9]{1,2}[.][0-9]{1,2})|([0-9]{1,2}[.][0-9]{1,2})"

    If strPattern <> "" Then
        strInput = Myrange.Value
        strReplace = ""

        With regEx
            .Global = True
            .MultiLine = True
            .IgnoreCase = False
            .Pattern = strPattern
        End With

        If regEx.test(strInput) Then
            remomveVers = regEx.Replace(strInput, strReplace)
        Else
            remomveVers = "Not matched"
        End If
    End If
End Function
</code>
You can use this function on your sheet (see screenshot below)
Comment: No the above code is not generating half output. I tried evaluating the formula too
Comment: i've added a screenshot of the formula working but as I said in my answer it will only work if the version number you want to remove is at the end of the text.
Comment: I've added a RegEx function that can remove #.#.# from anywhere in the text.  I'm no RegEx expert so the string pattern could most likely be improved but it does work.
Comment: Gordon can you please check for following inputs Adobe AIR (Unknown Version), 360 Secure Browser, Android Browser, Dolphin, Google Chrome (GoogleTV), Internet Explorer Mobile, Microsoft Internet Explorer 5.23 (Macintosh), Microsoft MSN Explorer, Mobile NetFront, Motorola MIB, Mozilla Firefox 3.0 beta, NetFront, Netscape Navigator 4.0 beta 3, Safari 3.0 (iPhone). Thanks a lot in advance
Comment: I've tested some of those and updated the string pattern so that it removes #.#.# or #.#. S o it will remove 3.0 or 5.23.
Comment: If you change both `100`'s to `LEN(A1)`, it will never fail due to an exceedingly long text string in A1.


GitHub how prevent pushing commits with personal (non corporate) email

Question: Is it possible to deny users to push commits to repo with a non corporate email?

for example only <code>*@mycompany.com</code> allowed
Comment: Note that Git alone can't really help you—anyone can put *anything* in as their email address—but GitHub can, by letting you control who gets to add commits to your repository via GitHub's "protected branches" add-on to Git.
Comment: This isn't exactly your question (I'm not going to VTC) but it might help you https://stackoverflow.com/questions/56069549/how-to-reject-git-push-based-on-some-rule
Comment: https://gist.github.com/tripleee/16767aa4137706fd896c is a simple wrapper which I'm using to prevent this.
Comment: @tripleee it helpful for local env only but I can't guarantee that every developer will install it correctly. So CI check in this case looks more convenient
Answer: I solved it using a custom Github Actions job:
<code># .github/workflows/check_email.yml
jobs:
  validate_email:
    name: Validate email
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v3
        with:
          fetch-depth: 0
      - name: Extract author email
        id: author
        run: |
          git log -2
          echo "::set-output name=EMAIL::$(git show -s --format='%ae' HEAD~0)"
      # TODO: Fail the workflow in future instead of adding comment
      - name: Validate author email
        if: ${{ !endsWith(steps.author.outputs.EMAIL, '@mycompany.com')  }}
        uses: actions/github-script@v6
        env:
          EMAIL: ${{ steps.author.outputs.EMAIL }}
        with:
          script: |
            const { EMAIL } = process.env
            await github.rest.issues.createComment({
              issue_number: context.issue.number,
              owner: context.repo.owner,
              repo: context.repo.repo,
              body: `⚠ We detect that you are using a non-corporate email \`${EMAIL}\` address to contribute to the repo. :(
            Please update your repo config \`.git/config\`:
            \`\`\`
              [user]
                name = Your Name
                email = email@example.com
            \`\`\`
            > You may see \`<id>+<name>@users.noreply.github.com\` email, then you need to turn off [Keep my email addresses private](https://github.com/settings/emails) setting in your account.
            `})
</code>
Comment: This looks like a decent solution. You might also want to look at creating a git commit hook. This will allow you to catch the error closer to the source.


Why doesnt the align-self: flex-end css property doesnt work on flex div?

Question: i want to align the click me button to the left of the div containing it.
below is my code,
render = () => {
    return (
        <Wrapper>

                Title
                <Description/>
                <ChildComponent/>

            <Actions>
                {((condition1 && !condition2) || !condition1) && (
                    <ActionText>
                        Hide
                    </ActionText>
                )}
                {condition1 ? (
                    condition2 ? (
                        <ButtonLink href="dddd">Click me</ButtonLink> // i want this                              //to be displayed at the extreme right of Actions div
                    ) : (<ButtonLink href="ee">Add</ButtonLink>)
                ) : null}
            </Actions>
        </Wrapper>
    }

const Wrapper = styled.div`
    position: fixed;
    overflow: auto;
    display: flex;
    flex-direction: column;
`;

 const Body = styled.div`
     display: flex;
     flex-direction: column;
 `;

  const Actions = styled.div`
      display: flex;
      flex-direction: row;
      justify-content: space-between;
  `;

   const ButtonLink = styled.a`
       display: flex;
       justify-content: center;
       align-items: center;
   `;

i want the click me button to be displayed at the extreme right of Actions div. i have tried to use align-self: flex-end to the ButtonLink click me and it doesnt work.
However adding margin-left to ButtonLink click me moves it.
i want to use flex-end. could someone help me fix this. thanks.
Answer: The align-self: flex-end; will only align something vertical (upp and down so to speak). It is a bit hard when not having a visual but try giving your Actions a flex-end
  const Actions = styled.div`
      display: flex;
      flex-direction: row;
      justify-content: flex-end;
  `;


Connecting values from PHP POST request to a variable in a python script to be executed

Question: Take for example a simple php form such as ,

<form action="welcome.php" method="post">
Name: <input type="text" name="name">

<input type="submit">
</form>

Is it possible to POST whatever value that a user input into a python script namely app.py which has a variable named as "name" eg:-
name = #This Variable needs to be populated with the value the user inputs to the form
print(name + " "+ "is my name")

Apologies about the vague question but I am quite new to programming and would be great if someone can at least point me in the right direction if this is possible. Another doubt here is on clicking the submit button how can I trigger the python script.
Answer: Your form is already sending a POST request, so it makes more sense to  post it directly to your Python application, if it's running on a web server. If for whatever reason you want to pass an HTTP request on to another web application, you can use PHP CURL extension. Take a look at this PHP + curl, HTTP POST sample code? and this https://www.php.net/manual/en/curl.examples-basic.php
If the Python app is not running on a web server, you can call it as a command line script from your PHP application. It would look something like this:
<?php
// welcome.php

$name = $_POST['name'];
$pythonScriptCall = 'python3 app.py name=' . $name;
$pythonScriptResult = '';
exec($pythonScriptCall, $pythonScriptResult);
echo $pythonScriptResult;


D3 area chart not rendering right

Question: I'm creating a D3 area chart, and the area is showing above the line rather than below.
Area chart with area appearing above line
Here's a fiddle: https://jsfiddle.net/8xsrmgzw/

//Read the data
d3.csv("https://raw.githubusercontent.com/kalidogg/UCB/main/DebtPenny6.csv",

  // When reading the csv, I must format variables:
  function(d){
    return { date : d3.timeParse("%Y-%m-%d")(d.date), value : d.value }
  },

  // Now I can use this dataset:
  function(data) {

    // Add X axis --> it is a date format
    var x = d3.scaleTime()
      .domain(d3.extent(data, function(d) { return d.date; }))
      .range([ 0, width ]);
    svg.append("g")
      .attr("transform", "translate(0," + height + ")")
      .call(d3.axisBottom(x));

    // Add Y axis
    var y = d3.scaleLinear()
      .domain([0, d3.max(data, function(d) { return +d.value; })])
      .range([ height, 0 ]);
    svg.append("g")
      .call(d3.axisLeft(y));

    // Add the area
    svg.append("path")
      .datum(data)
      .attr("fill", "#cce5df")
      .attr("stroke", "#69b3a2")
      .attr("stroke-width", 1.5)
      .attr("d", d3.area()
        .x(function(d) { return x(d.date) })
        .y0(y(0))
        .y1(function(d) { return y(d.value) })
        )

})

</script>

Thanks.
Answer: There are a couple issues. First, you need to sort your data by the date before drawing the area. Second, your dataset contains null values. In the example below, I have filtered those out, but you could consider doing something like these examples to indicate where data is missing.
Also, setting a stroke color on the area will create an outline of the area, including on the sides and bottom. If you just want a line outlining the top of the area, then you can add a separate path and use area.lineY1() to get a line generator for the top line of the area.

<!DOCTYPE html>

    <meta charset="UTF-8">

Comment: Perfect! Dan, thank you so much, especially for the tips on dealing with null values. Your help is much appreciated

D3 area chart not rendering right


Graphing x-y coordinates from a mouse with Processing

Question: I've found this really cool site on interfacing an Arduino to an optical mouse to read out x-y readings from it. I've done it, and it's working nicely.
Then I was thinking, 'Why not plot all this to become a graph?' and I came across Processing.
I am aware that Processing has an example named 'MouseSignal'
This example is the EXACT thing that I want to write with Processing. But, the only change is that, I want to use the x-y coordinates from the mouse that is attached to the Arduino and ask Processing to generate a 'real-time' graph of the coordinate.
Thanks!
Comment: I think you mean "MouseSignals", for anyone trying to figure out this question.
Comment: Can you share the website for interfacing Arduino to optical mouse?  That does sounds cool.
Comment: "Can you share the website for interfacing Arduino to optical mouse? That does sounds cool."

Here is it - http://www.synbio.org.uk/component/content/article/46-instrumentation-news/1234-interfacing-an-optical-mouse-sensor-to-your-arduino.html
Answer: Change the spot in the code where it says:
xvals[width-1] = mouseX;
yvals[width-1] = mouseY;

Replace mouseX and mouseY with the values coming from the Arduino. You may need to scale these values to fit within the axes.
Comment: I believe I need to add in

    import processing.serial.*;

at the start as well as

    println(Serial.list());
      g_serial = new Serial(this, Serial.list()[1], 115200, 'N', 8, 1.0);

under void setup?
Comment: If that's how you are getting the data off the Arduino, then yes you would need to do that (and also define Serial g_serial; outside of setup()). Have you looked into the official Arduino processing library instead of just the serial interface, though? http://www.arduino.cc/playground/Interfacing/Processing
Comment: I've looked at it, but don't quite understand, since I haven't tried it. Maybe I'll understand after trying it out.

And thank you for getting me this far!


find pattern and characters up to space, and move captured pattern to end of line sed

Question: I would like to find a particular pattern ("k__"), and any characters after it, up to a space, and then move that captured pattern to the end of the line
With this example file:
cat test.file
37099   k__Eukaryota species:s__Isochrysis galbana;genus:g__Isochrysis;family:f__Isochrysidaceae;order:o__Isochrysidales;class:c__Haptophyta;phylum:p__Haptista
73015   k__Eukaryota species:s__Monodus sp. CCMP505;genus:g__Monodus;family:f__Pleurochloridaceae;order:o__Mischococcales;class:c__Xanthophyceae;phylum:p__
73015   k__Eukaryota species:s__Monodus sp. CCMP505;genus:g__Monodus;family:f__Pleurochloridaceae;order:o__Mischococcales;class:c__Xanthophyceae;phylum:p__
73015   k__Eukaryota species:s__Monodus sp. CCMP505;genus:g__Monodus;family:f__Pleurochloridaceae;order:o__Mischococcales;class:c__Xanthophyceae;phylum:p__
73015   k__Eukaryota species:s__Monodus sp. CCMP505;genus:g__Monodus;family:f__Pleurochloridaceae;order:o__Mischococcales;class:c__Xanthophyceae;phylum:p__
73015   k__Eukaryota species:s__Monodus sp. CCMP505;genus:g__Monodus;family:f__Pleurochloridaceae;order:o__Mischococcales;class:c__Xanthophyceae;phylum:p__
43925   k__Eukaryota species:s__Nannochloropsis oculata;genus:g__Nannochloropsis;family:f__Monodopsidaceae;order:o__Eustigmatales;class:c__Eustigmatophyceae;phylum:p__
43925   k__Eukaryota species:s__Nannochloropsis oculata;genus:g__Nannochloropsis;family:f__Monodopsidaceae;order:o__Eustigmatales;class:c__Eustigmatophyceae;phylum:p__
43925   k__Eukaryota species:s__Nannochloropsis oculata;genus:g__Nannochloropsis;family:f__Monodopsidaceae;order:o__Eustigmatales;class:c__Eustigmatophyceae;phylum:p__
43925   k__Bacteria species:s__Nannochloropsis oculata;genus:g__Nannochloropsis;family:f__Monodopsidaceae;order:o__Eustigmatales;class:c__Eustigmatophyceae;phylum:p__

So, Id like to match "k__Eukaryota" and "k__Bacteria" (and other patterns that start with k__) and then move those captured matches to the end of the line : e.g. desired output=
37099    species:s__Isochrysis galbana;genus:g__Isochrysis;family:f__Isochrysidaceae;order:o__Isochrysidales;class:c__Haptophyta;phylum:p__Haptista k__Eukaryota
73015    species:s__Monodus sp. CCMP505;genus:g__Monodus;family:f__Pleurochloridaceae;order:o__Mischococcales;class:c__Xanthophyceae;phylum:p__ k__Eukaryota
73015    species:s__Monodus sp. CCMP505;genus:g__Monodus;family:f__Pleurochloridaceae;order:o__Mischococcales;class:c__Xanthophyceae;phylum:p__ k__Eukaryota
73015    species:s__Monodus sp. CCMP505;genus:g__Monodus;family:f__Pleurochloridaceae;order:o__Mischococcales;class:c__Xanthophyceae;phylum:p__ k__Eukaryota
73015    species:s__Monodus sp. CCMP505;genus:g__Monodus;family:f__Pleurochloridaceae;order:o__Mischococcales;class:c__Xanthophyceae;phylum:p__ k__Eukaryota
73015    species:s__Monodus sp. CCMP505;genus:g__Monodus;family:f__Pleurochloridaceae;order:o__Mischococcales;class:c__Xanthophyceae;phylum:p__ k__Eukaryota
43925    species:s__Nannochloropsis oculata;genus:g__Nannochloropsis;family:f__Monodopsidaceae;order:o__Eustigmatales;class:c__Eustigmatophyceae;phylum:p__ k__Eukaryota
43925    species:s__Nannochloropsis oculata;genus:g__Nannochloropsis;family:f__Monodopsidaceae;order:o__Eustigmatales;class:c__Eustigmatophyceae;phylum:p__ k__Eukaryota
43925    species:s__Nannochloropsis oculata;genus:g__Nannochloropsis;family:f__Monodopsidaceae;order:o__Eustigmatales;class:c__Eustigmatophyceae;phylum:p__ k__Eukaryota
43925    species:s__Nannochloropsis oculata;genus:g__Nannochloropsis;family:f__Monodopsidaceae;order:o__Eustigmatales;class:c__Eustigmatophyceae;phylum:p__ k__Bacteria

I thought it woudl be easy but I can;t get it to go. Here is what ive tried:
cat test.file | gsed -E 's#(.*k__)(k__\w\+)(.*)#\1\3\2#'

Cupture text until pattern, then match (cpature pattern and any word characters up to whitespace) then capture to the end of the line and then change the order of capturing groups.
I think I can back reference these patterns to change the order but Im prob. not matching them correctly. How to capture up to my pattern, the pattern ("K__xyz") and then match to end of line, capture those groups, and reorganize? Is this the right approach?
Any help is much appreciated!
LP
Comment: `sed -E 's/^([^k]{1,})([^ ]{1,})(.*)$/\1\3 \2/' test.file`
Comment: Did any of the solutions work? Please let know if you still need help with this.
Answer: if you want to edit original file, add '-i' option;
sed -i -r 's/(.*)(k__[^ ]*)( .*)/\1\3 \2/g' test.file
if you want to save result to other file, remove '-i' option;
sed -r 's/(.*)(k__[^ ]*)( .*)/\1\3 \2/g' test.file > new.file
my test result:
szvp000006656:/home # cat test.file
37099   k__Eukaryota species:s__Isochrysis galbana;genus:g__Isochrysis;family:f__Isochrysidaceae;order:o__Isochrysidales;class:c__Haptophyta;phylum:p__Haptista

szvp000006656:/home # sed -r 's/(.*)(k__[^ ]*)( .*)/\1\3 \2/g' test.file > new.file
szvp000006656:/home # cat new.file
37099    species:s__Isochrysis galbana;genus:g__Isochrysis;family:f__Isochrysidaceae;order:o__Isochrysidales;class:c__Haptophyta;phylum:p__Haptista k__Eukaryota

szvp000006656:/home # sed -i -r 's/(.*)(k__[^ ]*)( .*)/\1\3 \2/g' test.file
szvp000006656:/home # cat test.file
37099    species:s__Isochrysis galbana;genus:g__Isochrysis;family:f__Isochrysidaceae;order:o__Isochrysidales;class:c__Haptophyta;phylum:p__Haptista k__Eukaryota

Note:

It is recommended to use https://regexr.com/ to debug regular syntax
Neither basic nor extended Posix/GNU regex recognizes the non-greedy quantifier; you need a later regex. Try this non-greedy regex [^/]* instead of .*? chaos-stackoverflow
Comment: You don't need the 1st capture group.  `sed -E 's/(k__[^ ]+) (.*)/\2 \1/'` works to simply edit the part of the line beginning with the match.
Answer: Use this Perl one-liner:
perl -lpe 's{^(.*?\s)(k__\S+)\s+(.*)}{$1$3 $2}' test.file > out.file

The Perl one-liner uses these command line flags:
-e : Tells Perl to look for code in-line, instead of in a file.
-p : Loop over the input one line at a time, assigning it to $_ by default. Add print $_ after each loop iteration.
-l : Strip the input line separator ("\n" on *NIX by default) before executing the code in-line, and append it when printing.
^ : Beginning of the line.
(.*?\s) : 0 or more of any characters (non-greedy), ending with whitespace, capture and store in variable $1.
(k__\S+) : Literal k__ followed by 1 or more non-whitespace characters, capture and store in variable $2.
\s+(.*) : 1 or more whitespace characters. Then 0 or more any characters, capture and store in variable $3.
SEE ALSO:
perldoc perlrun: how to execute the Perl interpreter: command line switches
perldoc perlre: Perl regular expressions (regexes)
Comment: `perl -pe 's/k__\S+//; $k=$&; s/$/ $k/' ` -- have perl remove the string, which is saved as `$&`, then stash that in `$k`, then replace the line end with `$k`  ... takes advantage of variables, which perl has but sed doesn't (other than the hold space).
Comment: Oh, or this: `perl -lpe 's/k__\S+//; $_="$_ $&"'`   ... anyways, yay perl.


How to solve a Definite Integral (calculus 2)

Question: I've begun to learn about these types of questions, however I still have a hard time knowing how to solve them and doing the actual computation. These three integrals are examples of the questions I am experiencing difficulty with.
Any help will be extremely appreciated.
$$\int_{-\surd 2}^{-2}\frac{\operatorname d y}{y\sqrt{y^2-1\;}}$$
$$\int_{-\sqrt{3}/3}^0 \frac{\operatorname d z}{1+z^2}$$
$$\int_{1/2}^{-\sqrt{2\;} / 2} \frac{\operatorname d x}{\sqrt{1-x^2\;}}$$
Comment: You'll need a trig substitution for the first one (unless you've dealt with hyperbolic functions); the second involved the arctangent function; the third, the arcsine function.  As **Taladris** says, particularly for exam problems, you _will_ be expected to know some basic anti-derivatives.
Comment: Use the Fundamental Theorem of Calculus. Together with the Fundamental Rule of Calculus Student: know your classic derivatives and antiderivatives.
Comment: I haven't actually learned any Trig Identities yet, I was given this today, I suspect maybe I will be taught this next class.
Answer: For the first one, use the substitution $\;t\colon=\color{red}-\sqrt{y^2-1}$ (the minus sign is related to the bounds).
You should have learnt the other two (arcsine and arctangent).
Answer: (1) $$\int_{-\sqrt 2}^{-2} \frac{\operatorname d y}{y\sqrt{y^2-1}}$$
Substitute $s^2 = y^2-1$ and $s\operatorname d s = y\operatorname d y$.
$$\int_{1}^{\sqrt 3}\frac{s\operatorname d s}{y\cdot y\sqrt{s^2}}$$
$$\int_{1}^{\sqrt 3}\frac{\operatorname d s}{s^2+1}$$
Use $\dfrac{\operatorname d \arctan s}{\operatorname d s} = \dfrac{1}{s^2+1}$
$$\Big[\arctan s\Big]_{s=1}^{s=\sqrt 3}$$
$$\arctan \sqrt 3 - \arctan 1$$
$$\frac{\pi}{12}$$
Answer: $(1)$ Let $$\displaystyle I = \int_{-\sqrt{2}}^{-2}\frac{1}{y\sqrt{y^2-1}}dy\;,$$ Let $\displaystyle y = -\sec \phi\;,$ Then $\displaystyle dy = -\sec \phi\cdot \tan \phi d \phi$ and changing Limit
We get $$\displaystyle I = \int_{\frac{\pi}{4}}^{\frac{\pi}{3}}\frac{-\sec \phi\cdot \tan \phi}{-\sec \phi\cdot \tan \phi} d\phi = \left[\phi\right]_{\frac{\pi}{4}}^{\frac{\pi}{3}} = \left(\frac{\pi}{4}-\frac{\pi}{3}\right) = \frac{\pi}{12}$$
$\bf{Another\; way::}$ Given $$\displaystyle I = \int_{-\sqrt{2}}^{-2}\frac{1}{y\sqrt{y^2-1}}dy\;,$$ Now Put $\displaystyle y = -\frac{1}{t}\;,$ Then $\displaystyle dy = \frac{1}{t^2}dt$ and Changing Limit, We get
$$\displaystyle I = -\int_{\frac{1}{\sqrt{2}}}^{\frac{1}{2}}\frac{1}{\sqrt{1-t^2}}dt = -\left[\sin^{-1}(t)\right]_{\frac{1}{\sqrt{2}}}^{\frac{1}{2}} = -\left[\sin^{-1}\left(
\frac{1}{2}\right)-\sin^{-1}\left(\frac{1}{\sqrt{2}}\right)\right]$$
So we get $$\displaystyle I = -\left[\sin^{-1}\left(
\sin \frac{\pi}{6}\right)-\sin^{-1}\left(\sin \frac{\pi}{4}\right)\right] = -\left[\frac{\pi}{6}-\frac{\pi}{4}\right] = \frac{\pi}{12}.$$
$(2)\;\;$ Let $$\displaystyle I = \int_{-\frac{1}{\sqrt{3}}}^{0}\frac{1}{1+z^2}dz$$
Put $z=\tan \phi$ and $dz = \sec^2 \phi$ and Changing Limit, We get
$$\displaystyle I = \int_{-\frac{\pi}{6}}^{0}\frac{\sec^2 \phi}{\sec^2 \phi}d\phi = \left[\phi\right]_{-\frac{\pi}{6}}^{0} = \left[0-\left(-\frac{\pi}{6}\right)\right] = \frac{\pi}{6}$$
$(3)\;\;$ Let $$\displaystyle I = \int_{\frac{1}{2}}^{-\frac{1}{\sqrt{2}}}\frac{1}{\sqrt{1-x^2}}dx$$
Put $x=\sin \phi\;,$ Then $dx = \cos \phi d\phi$ and Changing Limit, We get
$$\displaystyle I = \int_{\frac{\pi}{6}}^{\frac{3\pi}{4}}\frac{\cos \phi}{\cos \phi}d\phi = \left[\phi\right]_{\frac{\pi}{6}}^{\frac{3\pi}{4}} = \left(\frac{3\pi}{4}-\frac{\pi}{6}\right) = \frac{7\pi}{12}.$$
Comment: how did you find the new values for the integral endpoints?
Comment: and thank you for your help.
Comment: When $y=-\sqrt{2}\;,$ Then $\displaystyle -\sqrt{2} = -\sec\phi\Rightarrow \sec\phi = \sqrt{2}\Rightarrow \cos \phi = \frac{1}{\sqrt{2}}$. So $\displaystyle \phi = \frac{\pi}{4}$ , Similarly for upper bond.


Verification of the limit of a succession

Question: $$\lim_{n\to +\infty} \frac{\ln(n+1)}{2n} = 0$$
Procedure.
$$\big|\frac{\ln(n+1)}{2n}\big| < \epsilon$$
Due to the fact that $n\to +\infty$ the absolute value is meaningless. Now we can say
The problem is that now I am stuck. I tried with some majorisations like
$$\ln(1+n) \leq 1+n$$ or
$$\ln(1+n) \geq \ln(n)$$
But they did not help me.
Is there a sort of easy way to proceed?
Comment: If you're trying to prove it through $\varepsilon$-$N$, you'll probably need to resort to the definition of logarithm, or to some known inequalities that you might have already been given in your textbook or something. Can you share this context?
Comment: @GitGud It's actually an exercise our professor left to us. I was indeed searching for some logarithms inequalities, yet I found nought.
Comment: So there are things you have covered. It's likely your professor gave you enough material to solve this. You need to try to get a sense of what that might be and share it in your question.
Answer: Let $(a_{n})_{n\geqslant 1}$ be a sequence defined by
$$a_{n}=\frac{\ln(n+1)}{cn},\quad c\in \mathbb{R}_{+}^{*}$$
By definition,
$$a_{n}\underset{n\to +\infty}{\sim }\ell \iff \forall \varepsilon>0\exists N\in \mathbb{N}, n\geqslant N:\quad |a_{n}-\ell|<\varepsilon. $$
that is,
$$\frac{\ln(n+1)}{cn}\underset{n\to +\infty}{\sim }0 \iff \forall \varepsilon>0\exists N\in \mathbb{N}, n\geqslant N:\quad \left|\frac{\ln(n+1)}{cn}-0\right|<\varepsilon. $$
Since that
$$\left|\frac{\ln(n+1)}{cn}-0\right|=\left|\frac{\ln(n+1)}{cn} \right|\leqslant \left|\frac{n+1}{cn}\right|=\frac{n+1}{cn}<\varepsilon \iff n>\frac{1}{c(\varepsilon-\frac{1}{c})}$$
Therefore,
Let $\varepsilon>0$ and $N\in\mathbb{N}$ such that $n>\frac{1}{c\left(\varepsilon-\frac{1}{c}\right)}$ with $c\in \mathbb{R}_{+}^{*}$. Then for all $n\in \mathbb{N}$ such that $n\geqslant N$, we have
$$\left|\frac{\ln(n+1)}{cn}-0 \right|=\left|\frac{\ln(n+1)}{cn} \right|\leqslant \left| \frac{n+1}{cn}\right|=\frac{n+1}{cn}=\frac{1}{c}+\frac{1}{cn}<\frac{1}{c}+\varepsilon-\frac{1}{c}=\varepsilon.$$
Note: We know that for all $x\in \mathbb{R}_{+}^{*}$ we have that
$$\frac{x-1}{x}\leqslant \ln(x)\leqslant x-1.$$
Reference: For all $x\in \mathbb{R}_{+}^{*}$ we have $\frac{x-1}{x}\leqslant \ln(x)\leqslant x-1$.
Comment: Insightful and brilliant!
Answer: First note
$$ e^t\ge1+t+\frac12t^2, t\ge0 $$
Let $t=\ln(1+n)$ and then $n=e^t-1$. So
$$ \frac{\ln(1+n)}{n}=\frac{t}{e^t-1}\le\frac{t}{t+\frac12t^2}=\frac{1}{1+\frac12t}=\frac{2}{2+\ln(1+n)}. $$
For $\forall \varepsilon>0$, letting
$$ \frac{2}{2+\ln(1+n)}<\varepsilon $$
gives
$$ n>e^{\frac{2(1-\varepsilon)}{\varepsilon}}-1. $$
Define
$$ N=\lfloor e^{\frac{2(1-\varepsilon)}{\varepsilon}}\rfloor+1 $$
Then when $n\ge N$, one has
$$ \bigg|\frac{\ln(1+n)}{n}-0\bigg|<\varepsilon $$
or
$$ \lim_{n\to\infty}\frac{\ln(1+n)}{n}=0. $$


Transform multiple return values to a custom string in default django admin interface

Question: I am returning three variables from a model method and want to display them on the admin interface:
def time_since(self):
   time_since = timezone.now() - self.date_opened
   return time_since.days, time_since.seconds//3600, (time_since.seconds//60)%60

Getting the value in admin.py
class TicketAdmin(admin.ModelAdmin):
    list_display = (
    'issue',
    'time_since',
    )

and this is getting displayed as (0,1,21). How do I transform it to 0 days, 1:21 ?
Answer: Assuming you've returned a tuple (0,1,21) then:
x = (0,1,21)

# Assumes that the values in your tuple will always be an integer.
s = '{:d} days, {:d}:{:d}'.format(*x)

print s # 0 days, 1:21

The documentation for the string formatting is given here
EDIT: In response to your comment I think you would adjust your code to return the string like so:
def time_since(self):
    time_since = timezone.now() - self.date_opened
    out = [time_since.days, time_since.seconds//3600, (time_since.seconds//60)%60]

    # As per Aamir Adnan's suggestion check whether day or days is applicable
    if x[0] == 1:
        return '{:d} day, {:d}:{:d}'.format(*x)
    else:
        return '{:d} days, {:d}:{:d}'.format(*x)

Comment: Just a suggestion: You might want to have a check for to pluralize word `day` or not. `1 days` will not sound correct.
Comment: where am I going to put that ?
Comment: @AamirAdnan I've edited the code with your suggestion :) there may be a simpler and more pythonic way of doing it but this should do the job.
Answer: You can use django built-in template filter timesince also:
from django.template.defaultfilters import timesince_filter

def time_since(self):
    return timesince_filter(self.date_opened) # e.g. yield 4 days, 6 hours

Comment: Updated my answer. You don't need to subtract dates as the `timesince_filter` will do it for you by looking into your settings `TIME_ZONE`
Comment: 'datetime.timedelta' object has no attribute 'year'. Why? I searched around in google and couldn't find anything related.
Comment: Very interesting and useful. But still getting "2 hours, 51 minutes" styling for the date. Not wrong, but not the format I was looking for. Thank you


The prime number $p$ is prime in $\mathbb{Q}(\sqrt{d})$ iff $d$ is not a quadratic residue modulo p

Question:
Theorem. The prime number $p$ is prime in $\mathbb{Q}(\sqrt{d})$ iff $d$ is not a quadratic residue modulo p.

Since this theorem has two directions, we have to prove two things. One way to do that is to assume that $d$ is quadratic residue, and to get the contradiction. My question is about the second part, about assuming that $p$ is not prime. I found the proof where it is said the following:
Assume that $p$ is not prime. Then, $p$ is not irreducible, so, there are $u,v \in \mathbb{Q}(\sqrt{d})$ such that $p=uv$ and $u,v$ are not unit elements. I won't continue writing this proof if it's not necessary, I have only one question: how come we concluded: $p$ is not prime $\Rightarrow$ $p$ is not irreducible? I know about the theorem that says that any prime in $\mathbb{Q}(\sqrt{d})$ is irreducible, but not vice versa. Can vice versa work in $\mathbb{Q}(\sqrt{d})$? Thank you.
Comment: @karim-ashli: That's related to my comment: in a field, every nonzero element is a unit, so nothing is a prime at all. So presumably the problem is actually asking about primes in the **ring of integers** of $\mathbb{Q}(\sqrt{d})$, rather than in $\mathbb{Q}(\sqrt{d})$ itself.
Comment: (@Karim-ashli: Note that you are missing "is not zero and is not a unit" in your definition of prime).
Comment: Note: Prime implies irreducible, but in rings of the form $\mathbb{Q}(\sqrt{d})$, irreducible does not necessarily imply prime. A standard example is $1+\sqrt{-5}$ in $\mathbb{Z}(\sqrt{-5})$, since $2\times 3 = (1+\sqrt{-5})(1+\sqrt{-5})$, and all of the factors are irreducible in the ring of integers $\mathbb{Z}(\sqrt{-5})$.
Comment: I thought the same, then the proof is not right?
Comment: P.S. I assume it means "in the ring of integers of $\mathbb{Q}(\sqrt{d})$"....
Comment: $p$ is prime iff ($\forall a,b \in \mathbb{Q}(\sqrt{d})$) $p | ab \Rightarrow p|a \vee p|b$
Comment: @karim-ashli All $p\in\Bbb Q(\sqrt d)$ have that property, because it's a field.
Comment: @Gae.S. what property exactly?
Comment: The one you just wrote: $$\forall a\in\Bbb Q(\sqrt d),\forall b\in\Bbb Q(\sqrt d),((p\mid a)\lor (p\mid b)\lor \neg (p\mid ab))$$
Comment: @karim-ashli everything non-zero is a unit in a field, Arturo mentioned the usual assumption when talking about number fields
Comment: I am questioning the proof so I thought you thought something else:)
Comment: As to whether the proof is valid, without seeing in full I don't know, but if all they did was prove that reducible non-primes `blah`, then it may be incorrect.
Comment: so, if we say $p\in \mathbb{N}$, then we could say: prime $\Leftrightarrow$ irreducible?
Comment: @karim-ashli: In the integers, yes. More generally, in a UFD, yes.
Answer: $\Bbb{Q}(\sqrt{d})$ is a field it has no non-trivial (prime) ideal.
For $d \in \Bbb{Z}, \not \in \Bbb{Z}^2$ then $(p)$ is a prime ideal of $R=\Bbb{Z}[\sqrt{d}] =\Bbb{Z}[x]/(x^2-d)$ iff $R/(p) = \Bbb{F}_p[x]/(x^2-d)$ is an integral domain iff  $x^2-d \in \Bbb{F}_p[x]$ is irreducible iff $d$ is a quadratic non-residue $\bmod p$.
With $d = m^2 D$ where $D$ is squarefree the ring of integers of $\Bbb{Q}(\sqrt{d})$ is $\Bbb{Z}[\sqrt{D}] $ or $\Bbb{Z}[\frac{1+\sqrt{D}}{2}] $, in the latter case there is the additional case of $(2)$ which is a prime ideal because $x^2+x+1 \in  \Bbb{F}_2[x]$ is irreducible.


Junit @Rule and @ClassRule

Question: I am writing JUnit4 test in which I am using TemporaryFolder rule. It seems that it works fine with both @Rule and @ClassRule. What is the difference between Junit @Rule and @ClassRule? Why should I use one and not another?
Answer: The distinction becomes clear when you have more than one test method in a class.
A @ClassRule has its before() method run before any of the test methods. Then all the test methods are run, and finally the rule's after() method. So if you have five test methods in a class, before() and after() will still only get run once each.
@ClassRule applies to a static method, and so has all the limitations inherent in that.
A @Rule causes tests to be run via the rule's apply() method, which can do things before and after the target method is run. If you have five test methods, the rule's apply() is called five times, as a wrapper around each method.
Use @ClassRule to set up something that can be reused by all the test methods, if you can achieve that in a static method.
Use @Rule to set up something that needs to be created a new, or reset, for each test method.
Comment: Simple, concise to the point –– Different from the official Javadoc.

Thanks!
Comment: Hands down, one of the only few easy explanations that make sense on @ClassRule
Comment: how about just use annotations BeforeClass and Before? why ClassRule and Rule is needed?
Answer: @Rule can not be set up to run before an @BeforeClass.
While @ClassRule must be on static method.
Answer: Ref: Annotates static fields that reference rules or methods that return them. A field must be public, static, and a subtype of TestRule. A method must be public static, and return a subtype of TestRule.
The Statement passed to the TestRule will run any BeforeClass methods, then the entire body of the test class (all contained methods, if it is a standard JUnit test class, or all contained classes, if it is a Suite), and finally any AfterClass methods.
https://junit.org/junit4/javadoc/4.12/org/junit/ClassRule.html

Junit @Rule and @ClassRule


determing x,y increase by angle?

Question: If I had a position of 0,0 and I had an angle of 45 degrees (or any number) and my velocity was 1  what would be the x,y increase?
For example if I had a 90 degree angle, and I had a velocity of 1.  Then because my angle is straight up, my increase would be 1y and 0x.
Not sure if this makes sense, I am programming a small game, that shoots on any angle, and I need to pass it x and y coordinates so it shoots on the same angle.
Thanks!
Just need the equation, or a tutorial
Answer: From $(0,0)$ at angle $\theta$ at velocity $1$ you get to $x=\cos\theta$, $y=\sin\theta$. You know trigonometry?
Comment: @Johnny - $x$ looks fine by $y $ does not, as you should find $\cos 45 = \sin 45 = 1/\sqrt{2} \approx 0.707$
Comment: It is the definition of the sine as opposite/hypotenuse.  Since your angle is measured from the $X$ axis, $v_x=v \cos(\theta), v_y=v \sin (\theta)$
Comment: used to! so if I had an angle of 45 it would just be x=cos45 and y=sin45   seems pretty straight forward.

So x=0.707  and y = 1
Comment: @Johnny, yes.$ $
Comment: oops, you are right, I did tan.  is Y always going to be sin? If so why is that?
Comment: When I wrote "yes" above, it was to the $x=\cos45^\circ$, $y=\sin45^\circ$, not to the $x=0.707$, $y=1$ (which I didn't see at the time, perhaps it wasn't there at the time).

determing x,y increase by angle?


Notation for sequences

Question: I am trying to write a small article, and I just want to know how would be a good way to present the maths I have written so that it looks professional.
I am trying to define a sequence $x_n$ of real numbers. So what I wrote in my article is:
Let $x_n$, $n \in \mathbb{N}$ be a sequence of real numbers.
However, it does not look very professional. How would I write the above sentence into something that looks professional? Note: I need to include $n \in \mathbb{N}$ in my sentence, so I think thats where my trouble is as $x_n$, $n \in \mathbb{N}$ seems a bit messy.
Thanks.
Comment: I prefer to present a sequence as $(x_n)_{n\in \mathbb{N}}$ (the parentheses are used to mean that a sequence is "ordered" in some way, just like finite $n$-tuples do). Other people use also $\{x_n\}_{n\in \mathbb{N}}$ (but I don't like this symbol, because curly brackets always denote sets and sets are not necessarily "ordered").
Comment: Is it an infinite sequence? Then maybe let $x_n$, where $n$ ranges over $\mathbb{N}$, be real numbers. Using more symbols is not necessarily more professional.
Comment: Thanks for your help guys! Yes it is an infinite sequence.
Comment: Just to add to the previous answers, in the Z formal specification language, curly brackets denote a set and angle brackets denote a sequence. [copied from this link (3rd Paragraph)](http://en.wikipedia.org/wiki/Bracket_%28mathematics%29)
Answer: I write my sequences as $\langle x_n \mid n \in \mathbb{N} \rangle$. Looks pretty cool I think. So you could say let $\langle x_n \mid n \in \mathbb{N} \rangle$ be a sequence in $\mathbb{R}$.
Comment: Notation $\langle \cdot \mid \cdot \rangle$ is used by physicists to denote inner product in the sequences space $\ell^2$; also, most mathematicians use the angular brackets $\langle \cdot ,\cdot \rangle$ to denote the inner product in a Hilbert space (hence also in $\ell^2$). Hence, IMHO, the notation you use can be very ambiguous.
Comment: I probably use this more since this is the standard notation for sequences in set theory.
Comment: I think it's not too ambiguous in this case. Probably no one would denote an inner product with $n \in \mathbb{N}$ in one of the sides of the angular brackets.
Comment: Big angle brackets is how Lamport denotes sequences in the TLA+ ecosystem. Of course he goes through great pains to make it clear a sequence is formally a function $x: \mathbb{N}\rightarrow S$
Comment: @Michael Deardeuff: In TLA+, angle brackets denote tuples, which are finite sequences. For example, $\langle a, b \rangle$. In other words, they are "tuple constructor" syntax. They cannot be used to define infinite sequences, so they cannot be used to answer the OP. Instead, one has to define a function $f$ with $\mathrm{DOMAIN}\ f = \mathit{Nat}$.
Comment: What notation would one use to denote a variable to which a sequence is assigned? Capital letter (e.g. A = ⟨a,b⟩)? Lowercase letter? Bold? Italic? Set variables are often capital letters. Some sets have special styling for their capital letters (as seen in this answer for natural and real numbers). Thoughts? (Should I break this out into a new question?)
Answer: The best notation for functions that I have encountered so far is by Leslie Lamport, described in his book on the temporal logic of actions, TLA+ (see Sec.5.2 on p.48, and Sec.6.4 on p.69).
In axiomatic set theory as formalized in TLA+, a function is a set that satisfies certain axioms about relevant syntactic constructs. I have found the syntax exceptionally practical and precise:

$f \triangleq [x \in S \mapsto e(x)]$ defines a function that maps elements of the set $S$ to the expression $e(x)$. Example of function constructor syntax: $f \triangleq [x \in \{3, 4\} \mapsto x - 1]$
$\mathrm{DOMAIN}\ f$ is the domain of function $f$. If $f$ is defined as above, then $\mathrm{DOMAIN}\ f = \{3, 4\}$
$f[x]$ function application, is a known value only if $f$ is a function (an axiom schema tells us that whatever is defined using the function constructor syntax from above is a function). Otherwise, it is some unspecified value (value is synonym for set in the set theory underlying TLA+).
$g(x)$ is operator application syntax, not function application. Read Sec.6.4. A function is a set, so we can write $\exists\ f$. An operator $g$ is syntax. Only the value $g(x)$ that results from applying the operator $g$ to the argument $x$ is a set.
This is the only approach that I have found across the mathematics, computer science, and engineering literature that addresses the question of what "f[x]" means when $x \notin \mathrm{DOMAIN}\ f$. To see what the problem is with traditional notation and education, see this discussion.
$f \in [S \rightarrow T]$ says that $f$ is an element of the set of functions with $\mathrm{DOMAIN}$ the set $S$ that take values in the set $T$. Note that "codomain" is not part of the notion of function. Only the range of a particular function makes sense, and the $T$ used to define some specific set of functions.

Using the above notation for the case of functions from the natural numbers (OP), a sequence of real numbers is a function
$f \in [\mathbb{N} \rightarrow \mathbb{R}]$

OLD ANSWER:
The notation $\{x_n\}_{n\in\mathbb{N} }$ is appropriate because a sequence is formally a function $x: \mathbb{N}\rightarrow S$ that maps natural numbers to elements of the set $S$ (codomain). The index $n$ denotes the argument of function $x$. The first notation corresponds to a set of numbers $\{x_n\}$ (the curly brackets do denote a set) indexed by the natural numbers.
Note also that the space of all real-valued sequences can be denoted as $\mathbb{R}^\mathbb{N}$, i.e., the set of all functions from the natural numbers $\mathbb{N}$ to the real numbers $\mathbb{R}$. See also this discussion:
What does it mean when a set is the exponent?
Comment: Well, the notation that looks similar to a set constructor has the $n \in \mathbb{N}$ outside the braces, so it is distinct from $\{x_n : n \in \mathbb{N}\}$. It could be recognized as different from a set constructor, but the difference is small. However, in any case it is informal, so it's meaning is unclear. In contrast, the TLA$^+$ notation is formally defined with axioms, so there isn't any ambiguity there. This is the problem with informal mathematics.
Comment: Doesn't this cause problems for the order of the elements in the sequence? idea from [this other question](http://math.stackexchange.com/q/323784/190328)
Comment: The order of the elements in the sequence is the order defined by the linear order between natural numbers. $f[0]$ is the first element, $f[1]$ the second, etc. If you prefer to start counting from 1, then just use $\mathbb{N} \setminus \{0\}$ as the function's domain: $f \in [\mathbb{N} \setminus \{0\} \rightarrow \mathbb{R}]$. For example, in TLA$^{+}$, a tuple is any function indexed over the set $1..n$, for example $\langle 6, 15 \rangle$ is the function $[x \in \{1, 2\} \mapsto \mathrm{IF}\; x = 1\; \mathrm{THEN}\; 6\; \mathrm{ELSE}\; 15$.
Comment: For the function-notation, there is no problem. I rather meant the set-notation.

Notation for sequences


Computing arctan in the range $-\pi\leq \theta\leq\pi$

Question: Here is the problem:
For each set of Cartesian coordinates (1-4) $(x, y)$, match the equivalent set of Polar coordinates (A-D) $(r, \theta)$, with $-\pi\leq \theta\leq \pi$.

$(-5.9, 2.9)$
$(-2.9, 6.1)$
$(5.4, 3.3)$
$(-6.9, 6.1)$

A. $(6.5742, -1.1139)$
B. $(6.3285, 1.0223)$
C. $(6.7543, -0.4438)$
D. $(9.2098, -0.8469)$
I have no issue with calculating the $r$ values, but I'm having trouble calculating the $\theta$ values. for example, for 1. I do:
$\theta = \tan^{-1}\left(\frac{y}{x}\right) = \tan^{-1}\left(\frac{2.9}{-5.9}\right) = -0.4568$
but I know that the answer is supposed to be $\theta = -1.1139$. How would I get to that number from the value I calculated in my calculator?
Comment: Welcome to MSE. It is in your best interest that you type your posts (using [MathJax](https://math.meta.stackexchange.com/questions/5020/mathjax-basic-tutorial-and-quick-reference)) instead of posting links to pictures.
Comment: Hint: $\sin{\theta} = y$ and $\cos{\theta} = x$ from the unit circle
Comment: Check this: https://math.stackexchange.com/q/2796641/42969
Comment: I got an angle of $2.6847$ for the first question, are the options even correct?
Comment: They ask you to match - that is you need to find the right matching from the lower list> It must be C then
Comment: https://en.m.wikipedia.org/wiki/Atan2#Definition_and_computation
Answer: The angles in the polar forms are all wrong.
The point $(-5.9, 2.9)_\text{Cartesian}$ is (1) in the 2nd quadrant, so has $\pi/2 = 1.57{\dots} < \theta < \pi = 3.14{\dots}$ and (2) is close to the point $(-6,3)_\text{Cartesian}$, which has polar angle $5\pi/6 = 2.6189{\dots}$.
If you just compute $\arctan(2.9/-5.9) = -0.45684{\dots}$, you can only get angles in quadrants 1 and 4 (because arctangent only gives angles in $(-\pi/2, \pi/2)$).  Since tangent has period $\pi$, there is always another angle in quadrants 2 or 3 having the same arctangent.  In this case, we use the signs of the coordinates to discover that the angle we want is in quadrant 2.  To get from quadrant 4 to quadrant 2 (remaining in the interval of angles $[-\pi, \pi]$) we must add one copy of the period, $\pi$, obtaining
$$  \arctan(2.9/-5.9) + \pi = 2.6847{\dots}  \text{.}  $$
If you had a point in quadrant 3, i.e., if both Cartesian coordinates are negative: To get to quadrant 3 from quadrant 1, remaining in the interval of angles $[-\pi,\pi]$, subtract $\pi$.
$(-2.9,6.1)_\text{Cartesian}$ should have polar angle $2.0145{\dots}$.
$(5.4,3.3)_\text{Cartesian}$ should have polar angle $0.54854{\dots}$.  $(5.4,3.3)_\text{Cartesian}$ is between the $x$-axis and the line $y = x$, so should have a positive polar angle of less than $45^\circ = \pi/4 = 0.78539{\dots}$
$(-6.9,6.1)_\text{Cartesian}$ has polar angle $2.4176{\dots}$.


Too many sleeping processes?

Question: I'm running Debian Lenny (x86_64) on a cloud VPS (Xen) and top command tells me there are 210 processes running and 209 are sleeping:
top - 14:49:29 up 15:18,  1 user,  load average: 0.09, 0.11, 0.05
Tasks: 210 total,   1 running, 209 sleeping,   0 stopped,   0 zombie
Cpu(s):  0.0%us,  0.0%sy,  0.0%ni,100.0%id,  0.0%wa,  0.0%hi,  0.0%si,  0.0%st
Mem:    532288k total,   437316k used,    94972k free,    30584k buffers
Swap:  1048568k total,      408k used,  1048160k free,   219772k cached

And here is what ps aux command gives me:
USER       PID %CPU %MEM    VSZ   RSS TTY      STAT START   TIME COMMAND
root         1  0.0  0.1  10380   812 ?        Ss   Sep30   0:00 init [2]
root         2  0.0  0.0      0     0 ?        S<   Sep30   0:00 [kthreadd]
root         3  0.0  0.0      0     0 ?        S<   Sep30   0:00 [migration/0]
root         4  0.0  0.0      0     0 ?        S<   Sep30   0:00 [ksoftirqd/0]
root         5  0.0  0.0      0     0 ?        S<   Sep30   0:00 [events/0]
root         6  0.0  0.0      0     0 ?        S<   Sep30   0:00 [khelper]
root         7  0.0  0.0      0     0 ?        S<   Sep30   0:05 [xenwatch]
root         8  0.0  0.0      0     0 ?        S<   Sep30   0:13 [xenbus]
root        10  0.0  0.0      0     0 ?        S<   Sep30   0:00 [migration/1]
root        11  0.0  0.0      0     0 ?        S<   Sep30   0:00 [ksoftirqd/1]
root        12  0.0  0.0      0     0 ?        S<   Sep30   0:00 [events/1]
root        13  0.0  0.0      0     0 ?        S<   Sep30   0:00 [migration/2]
root        14  0.0  0.0      0     0 ?        S<   Sep30   0:00 [ksoftirqd/2]
root        15  0.0  0.0      0     0 ?        S<   Sep30   0:00 [events/2]
root        16  0.0  0.0      0     0 ?        S<   Sep30   0:00 [migration/3]
root        17  0.0  0.0      0     0 ?        S<   Sep30   0:00 [ksoftirqd/3]
root        18  0.0  0.0      0     0 ?        S<   Sep30   0:00 [events/3]
root        19  0.0  0.0      0     0 ?        S<   Sep30   0:00 [migration/4]
root        20  0.0  0.0      0     0 ?        S<   Sep30   0:00 [ksoftirqd/4]
root        21  0.0  0.0      0     0 ?        S<   Sep30   0:00 [events/4]
root        22  0.0  0.0      0     0 ?        S<   Sep30   0:00 [migration/5]
root        23  0.0  0.0      0     0 ?        S<   Sep30   0:00 [ksoftirqd/5]
root        24  0.0  0.0      0     0 ?        S<   Sep30   0:00 [events/5]
root        25  0.0  0.0      0     0 ?        S<   Sep30   0:00 [migration/6]
root        26  0.0  0.0      0     0 ?        S<   Sep30   0:00 [ksoftirqd/6]
root        27  0.0  0.0      0     0 ?        S<   Sep30   0:00 [events/6]
root        28  0.0  0.0      0     0 ?        S<   Sep30   0:00 [migration/7]
root        29  0.0  0.0      0     0 ?        S<   Sep30   0:00 [ksoftirqd/7]
root        30  0.0  0.0      0     0 ?        S<   Sep30   0:00 [events/7]
root        31  0.0  0.0      0     0 ?        S<   Sep30   0:00 [migration/8]
root        32  0.0  0.0      0     0 ?        S<   Sep30   0:00 [ksoftirqd/8]
root        33  0.0  0.0      0     0 ?        S<   Sep30   0:00 [events/8]
root        34  0.0  0.0      0     0 ?        S<   Sep30   0:00 [migration/9]
root        35  0.0  0.0      0     0 ?        S<   Sep30   0:00 [ksoftirqd/9]
root        36  0.0  0.0      0     0 ?        S<   Sep30   0:00 [events/9]
root        37  0.0  0.0      0     0 ?        S<   Sep30   0:00 [migration/10]
root        38  0.0  0.0      0     0 ?        S<   Sep30   0:00 [ksoftirqd/10]
root        39  0.0  0.0      0     0 ?        S<   Sep30   0:04 [events/10]
root        40  0.0  0.0      0     0 ?        S<   Sep30   0:00 [migration/11]
root        41  0.0  0.0      0     0 ?        S<   Sep30   0:00 [ksoftirqd/11]
root        42  0.0  0.0      0     0 ?        S<   Sep30   0:00 [events/11]
root        43  0.0  0.0      0     0 ?        S<   Sep30   0:00 [migration/12]
root        44  0.0  0.0      0     0 ?        S<   Sep30   0:00 [ksoftirqd/12]
root        45  0.0  0.0      0     0 ?        S<   Sep30   0:00 [events/12]
root        46  0.0  0.0      0     0 ?        S<   Sep30   0:00 [migration/13]
root        47  0.0  0.0      0     0 ?        S<   Sep30   0:00 [ksoftirqd/13]
root        48  0.0  0.0      0     0 ?        S<   Sep30   0:00 [events/13]
root        49  0.0  0.0      0     0 ?        S<   Sep30   0:00 [migration/14]
root        50  0.0  0.0      0     0 ?        S<   Sep30   0:00 [ksoftirqd/14]
root        51  0.0  0.0      0     0 ?        S<   Sep30   0:00 [events/14]
root        52  0.0  0.0      0     0 ?        S<   Sep30   0:00 [migration/15]
root        53  0.0  0.0      0     0 ?        S<   Sep30   0:00 [ksoftirqd/15]
root        54  0.0  0.0      0     0 ?        S<   Sep30   0:00 [events/15]
root        55  0.0  0.0      0     0 ?        S<   Sep30   0:00 [kintegrityd/0]
root        56  0.0  0.0      0     0 ?        S<   Sep30   0:00 [kintegrityd/1]
root        57  0.0  0.0      0     0 ?        S<   Sep30   0:00 [kintegrityd/2]
root        58  0.0  0.0      0     0 ?        S<   Sep30   0:00 [kintegrityd/3]
root        59  0.0  0.0      0     0 ?        S<   Sep30   0:00 [kintegrityd/4]
root        60  0.0  0.0      0     0 ?        S<   Sep30   0:00 [kintegrityd/5]
root        61  0.0  0.0      0     0 ?        S<   Sep30   0:00 [kintegrityd/6]
root        62  0.0  0.0      0     0 ?        S<   Sep30   0:00 [kintegrityd/7]
root        63  0.0  0.0      0     0 ?        S<   Sep30   0:00 [kintegrityd/8]
root        64  0.0  0.0      0     0 ?        S<   Sep30   0:00 [kintegrityd/9]
root        65  0.0  0.0      0     0 ?        S<   Sep30   0:00 [kintegrityd/10]
root        66  0.0  0.0      0     0 ?        S<   Sep30   0:00 [kintegrityd/11]
root        67  0.0  0.0      0     0 ?        S<   Sep30   0:00 [kintegrityd/12]
root        68  0.0  0.0      0     0 ?        S<   Sep30   0:00 [kintegrityd/13]
root        69  0.0  0.0      0     0 ?        S<   Sep30   0:00 [kintegrityd/14]
root        70  0.0  0.0      0     0 ?        S<   Sep30   0:00 [kintegrityd/15]
root        71  0.0  0.0      0     0 ?        S<   Sep30   0:00 [kblockd/0]
root        72  0.0  0.0      0     0 ?        S<   Sep30   0:00 [kblockd/1]
root        73  0.0  0.0      0     0 ?        S<   Sep30   0:00 [kblockd/2]
root        74  0.0  0.0      0     0 ?        S<   Sep30   0:00 [kblockd/3]
root        75  0.0  0.0      0     0 ?        S<   Sep30   0:00 [kblockd/4]
root        76  0.0  0.0      0     0 ?        S<   Sep30   0:00 [kblockd/5]
root        77  0.0  0.0      0     0 ?        S<   Sep30   0:00 [kblockd/6]
root        78  0.0  0.0      0     0 ?        S<   Sep30   0:00 [kblockd/7]
root        79  0.0  0.0      0     0 ?        S<   Sep30   0:00 [kblockd/8]
root        80  0.0  0.0      0     0 ?        S<   Sep30   0:00 [kblockd/9]
root        81  0.0  0.0      0     0 ?        S<   Sep30   0:00 [kblockd/10]
root        82  0.0  0.0      0     0 ?        S<   Sep30   0:00 [kblockd/11]
root        83  0.0  0.0      0     0 ?        S<   Sep30   0:00 [kblockd/12]
root        84  0.0  0.0      0     0 ?        S<   Sep30   0:00 [kblockd/13]
root        85  0.0  0.0      0     0 ?        S<   Sep30   0:00 [kblockd/14]
root        86  0.0  0.0      0     0 ?        S<   Sep30   0:00 [kblockd/15]
root        87  0.0  0.0      0     0 ?        S<   Sep30   0:00 [cqueue]
root        88  0.0  0.0      0     0 ?        S<   Sep30   0:00 [kseriod]
root        89  0.0  0.0      0     0 ?        S    Sep30   0:00 [pdflush]
root        90  0.0  0.0      0     0 ?        S    Sep30   0:00 [pdflush]
root        91  0.0  0.0      0     0 ?        S<   Sep30   0:00 [kswapd0]
root        92  0.0  0.0      0     0 ?        S<   Sep30   0:00 [aio/0]
root        93  0.0  0.0      0     0 ?        S<   Sep30   0:00 [aio/1]
root        94  0.0  0.0      0     0 ?        S<   Sep30   0:00 [aio/2]
root        95  0.0  0.0      0     0 ?        S<   Sep30   0:00 [aio/3]
root        96  0.0  0.0      0     0 ?        S<   Sep30   0:00 [aio/4]
root        97  0.0  0.0      0     0 ?        S<   Sep30   0:00 [aio/5]
root        98  0.0  0.0      0     0 ?        S<   Sep30   0:00 [aio/6]
root        99  0.0  0.0      0     0 ?        S<   Sep30   0:00 [aio/7]
root       100  0.0  0.0      0     0 ?        S<   Sep30   0:00 [aio/8]
root       101  0.0  0.0      0     0 ?        S<   Sep30   0:00 [aio/9]
root       102  0.0  0.0      0     0 ?        S<   Sep30   0:00 [aio/10]
root       103  0.0  0.0      0     0 ?        S<   Sep30   0:00 [aio/11]
root       104  0.0  0.0      0     0 ?        S<   Sep30   0:00 [aio/12]
root       105  0.0  0.0      0     0 ?        S<   Sep30   0:00 [aio/13]
root       106  0.0  0.0      0     0 ?        S<   Sep30   0:00 [aio/14]
root       107  0.0  0.0      0     0 ?        S<   Sep30   0:00 [aio/15]
root       108  0.0  0.0      0     0 ?        S<   Sep30   0:00 [kpsmoused]
root       167  0.0  0.0      0     0 ?        S<   Sep30   0:00 [net_accel/0]
root       168  0.0  0.0      0     0 ?        S<   Sep30   0:00 [net_accel/1]
root       169  0.0  0.0      0     0 ?        S<   Sep30   0:00 [net_accel/2]
root       170  0.0  0.0      0     0 ?        S<   Sep30   0:00 [net_accel/3]
root       171  0.0  0.0      0     0 ?        S<   Sep30   0:00 [net_accel/4]
root       172  0.0  0.0      0     0 ?        S<   Sep30   0:00 [net_accel/5]
root       173  0.0  0.0      0     0 ?        S<   Sep30   0:00 [net_accel/6]
root       174  0.0  0.0      0     0 ?        S<   Sep30   0:00 [net_accel/7]
root       175  0.0  0.0      0     0 ?        S<   Sep30   0:00 [net_accel/8]
root       176  0.0  0.0      0     0 ?        S<   Sep30   0:00 [net_accel/9]
root       177  0.0  0.0      0     0 ?        S<   Sep30   0:00 [net_accel/10]
root       178  0.0  0.0      0     0 ?        S<   Sep30   0:00 [net_accel/11]
root       179  0.0  0.0      0     0 ?        S<   Sep30   0:00 [net_accel/12]
root       180  0.0  0.0      0     0 ?        S<   Sep30   0:00 [net_accel/13]
root       181  0.0  0.0      0     0 ?        S<   Sep30   0:00 [net_accel/14]
root       182  0.0  0.0      0     0 ?        S<   Sep30   0:00 [net_accel/15]
root       315  0.0  0.0      0     0 ?        S<   Sep30   0:00 [xfs_mru_cache]
root       316  0.0  0.0      0     0 ?        S<   Sep30   0:00 [xfslogd/0]
root       317  0.0  0.0      0     0 ?        S<   Sep30   0:00 [xfslogd/1]
root       318  0.0  0.0      0     0 ?        S<   Sep30   0:00 [xfslogd/2]
root       319  0.0  0.0      0     0 ?        S<   Sep30   0:00 [xfslogd/3]
root       320  0.0  0.0      0     0 ?        S<   Sep30   0:00 [xfslogd/4]
root       321  0.0  0.0      0     0 ?        S<   Sep30   0:00 [xfslogd/5]
root       322  0.0  0.0      0     0 ?        S<   Sep30   0:00 [xfslogd/6]
root       323  0.0  0.0      0     0 ?        S<   Sep30   0:00 [xfslogd/7]
root       324  0.0  0.0      0     0 ?        S<   Sep30   0:00 [xfslogd/8]
root       325  0.0  0.0      0     0 ?        S<   Sep30   0:00 [xfslogd/9]
root       326  0.0  0.0      0     0 ?        S<   Sep30   0:00 [xfslogd/10]
root       327  0.0  0.0      0     0 ?        S<   Sep30   0:00 [xfslogd/11]
root       328  0.0  0.0      0     0 ?        S<   Sep30   0:00 [xfslogd/12]
root       329  0.0  0.0      0     0 ?        S<   Sep30   0:00 [xfslogd/13]
root       330  0.0  0.0      0     0 ?        S<   Sep30   0:00 [xfslogd/14]
root       331  0.0  0.0      0     0 ?        S<   Sep30   0:00 [xfslogd/15]
root       332  0.0  0.0      0     0 ?        S<   Sep30   0:00 [xfsdatad/0]
root       333  0.0  0.0      0     0 ?        S<   Sep30   0:00 [xfsdatad/1]
root       334  0.0  0.0      0     0 ?        S<   Sep30   0:00 [xfsdatad/2]
root       335  0.0  0.0      0     0 ?        S<   Sep30   0:00 [xfsdatad/3]
root       336  0.0  0.0      0     0 ?        S<   Sep30   0:00 [xfsdatad/4]
root       337  0.0  0.0      0     0 ?        S<   Sep30   0:00 [xfsdatad/5]
root       338  0.0  0.0      0     0 ?        S<   Sep30   0:00 [xfsdatad/6]
root       339  0.0  0.0      0     0 ?        S<   Sep30   0:00 [xfsdatad/7]
root       340  0.0  0.0      0     0 ?        S<   Sep30   0:00 [xfsdatad/8]
root       341  0.0  0.0      0     0 ?        S<   Sep30   0:00 [xfsdatad/9]
root       342  0.0  0.0      0     0 ?        S<   Sep30   0:00 [xfsdatad/10]
root       343  0.0  0.0      0     0 ?        S<   Sep30   0:00 [xfsdatad/11]
root       344  0.0  0.0      0     0 ?        S<   Sep30   0:00 [xfsdatad/12]
root       345  0.0  0.0      0     0 ?        S<   Sep30   0:00 [xfsdatad/13]
root       346  0.0  0.0      0     0 ?        S<   Sep30   0:00 [xfsdatad/14]
root       347  0.0  0.0      0     0 ?        S<   Sep30   0:00 [xfsdatad/15]
root       399  0.0  0.0      0     0 ?        S<   Sep30   0:00 [jfsIO]
root       400  0.0  0.0      0     0 ?        S<   Sep30   0:00 [jfsCommit]
root       401  0.0  0.0      0     0 ?        S<   Sep30   0:00 [jfsCommit]
root       402  0.0  0.0      0     0 ?        S<   Sep30   0:00 [jfsCommit]
root       403  0.0  0.0      0     0 ?        S<   Sep30   0:00 [jfsCommit]
root       404  0.0  0.0      0     0 ?        S<   Sep30   0:00 [jfsCommit]
root       405  0.0  0.0      0     0 ?        S<   Sep30   0:00 [jfsCommit]
root       406  0.0  0.0      0     0 ?        S<   Sep30   0:00 [jfsCommit]
root       407  0.0  0.0      0     0 ?        S<   Sep30   0:00 [jfsCommit]
root       408  0.0  0.0      0     0 ?        S<   Sep30   0:00 [jfsCommit]
root       409  0.0  0.0      0     0 ?        S<   Sep30   0:00 [jfsCommit]
root       410  0.0  0.0      0     0 ?        S<   Sep30   0:00 [jfsCommit]
root       411  0.0  0.0      0     0 ?        S<   Sep30   0:00 [jfsCommit]
root       412  0.0  0.0      0     0 ?        S<   Sep30   0:00 [jfsCommit]
root       413  0.0  0.0      0     0 ?        S<   Sep30   0:00 [jfsCommit]
root       414  0.0  0.0      0     0 ?        S<   Sep30   0:00 [jfsCommit]
root       415  0.0  0.0      0     0 ?        S<   Sep30   0:00 [jfsCommit]
root       416  0.0  0.0      0     0 ?        S<   Sep30   0:00 [jfsSync]
root       673  0.0  0.0      0     0 ?        S<   Sep30   0:00 [kjournald]
root       727  0.0  0.1  16840   960 ?        S<s  Sep30   0:00 udevd --daemon
root      1273  0.0  0.3 122036  2016 ?        Sl   Sep30   0:00 /usr/sbin/rsyslogd -c3
root      1306  0.0  0.2  48960  1224 ?        Ss   Sep30   0:00 /usr/sbin/sshd
root      1809  0.0  0.2  21276  1076 ?        Ss   Sep30   0:00 /usr/sbin/cron
root      1873  0.0  1.5  41460  8360 ?        Ss   Sep30   0:02 /usr/sbin/munin-node
root      1896  0.0  0.1   3864   608 tty1     Ss+  Sep30   0:00 /sbin/getty 38400 tty1
root      1897  0.0  0.1   3864   604 tty2     Ss+  Sep30   0:00 /sbin/getty 38400 tty2
root      1898  0.0  0.1   3864   604 tty3     Ss+  Sep30   0:00 /sbin/getty 38400 tty3
root      1899  0.0  0.1   3864   608 tty4     Ss+  Sep30   0:00 /sbin/getty 38400 tty4
root      1900  0.0  0.1   3864   608 tty5     Ss+  Sep30   0:00 /sbin/getty 38400 tty5
root      1901  0.0  0.1   3864   604 tty6     Ss+  Sep30   0:00 /sbin/getty 38400 tty6
101       4526  0.0  0.1  42820  1052 ?        Ss   12:27   0:00 /usr/sbin/exim4 -bd -q30m
root      8865  0.0  0.2  11668  1432 pts/0    S    13:18   0:00 /bin/sh /usr/bin/mysqld_safe
mysql     8980  0.0  9.0 175284 48368 pts/0    Sl   13:18   0:05 /usr/sbin/mysqld --basedir=/usr --datadir=/var/lib/mysql --user=mysql --pid-file=/var/run/my
root      8981  0.0  0.1   6480   684 pts/0    S    13:18   0:00 logger -t mysqld -p daemon.error
root     13730  0.0  0.8 149144  4712 ?        Ss   14:05   0:00 /usr/bin/php5-fpm --fpm-config /etc/php5/fpm/php5-fpm.conf
www-data 13731  0.2 11.4 172756 61136 ?        S    14:05   0:05 /usr/bin/php5-fpm --fpm-config /etc/php5/fpm/php5-fpm.conf
www-data 13732  0.2  8.9 158516 47712 ?        S    14:05   0:05 /usr/bin/php5-fpm --fpm-config /etc/php5/fpm/php5-fpm.conf
www-data 13733  0.1  8.1 156576 43468 ?        S    14:05   0:04 /usr/bin/php5-fpm --fpm-config /etc/php5/fpm/php5-fpm.conf
root     14601  0.0  0.2  30600  1240 ?        Ss   14:15   0:00 nginx: master process /usr/sbin/nginx
www-data 14602  0.0  0.3  30976  1836 ?        S    14:15   0:00 nginx: worker process
www-data 14603  0.0  0.3  30976  1836 ?        S    14:15   0:00 nginx: worker process
www-data 14604  0.0  0.5  31552  2852 ?        S    14:15   0:00 nginx: worker process
www-data 14605  0.0  0.4  31240  2580 ?        S    14:15   0:00 nginx: worker process
www-data 14606  0.0  0.3  30976  1836 ?        S    14:15   0:00 nginx: worker process
www-data 14607  0.0  0.3  30976  1836 ?        S    14:15   0:00 nginx: worker process
www-data 14608  0.0  0.4  31244  2536 ?        S    14:15   0:00 nginx: worker process
www-data 14609  0.0  0.5  31544  2788 ?        S    14:15   0:00 nginx: worker process
root     17169  0.0  0.2  17456  1160 pts/0    R+   14:45   0:00 ps aux
root     26391  0.0  0.6  66168  3284 ?        Ss   10:32   0:00 sshd: root@notty
root     26394  0.0  0.3  42376  2120 ?        Ss   10:32   0:00 /usr/lib/openssh/sftp-server
root     31500  0.0  0.6  66140  3248 ?        Ss   11:33   0:00 sshd: root@pts/0
root     31503  0.0  0.3  20248  1924 pts/0    Ss   11:33   0:00 -bash
root     31509  0.0  0.6  66168  3264 ?        Ss   11:34   0:00 sshd: root@notty
root     31512  0.0  0.3  42180  1984 ?        Ss   11:34   0:00 /usr/lib/openssh/sftp-server

I'm wondering if this is normal situation? Do I need all of those process?
Thanks for any suggestions!
Answer:
I'm wondering if this is normal situation? Do I need all of those process?

It is normal for a server with no load. Many of the processes is the kernel threads. Many core - many processes(you have 16 core).
Answer: The total number of sleeping processes is not important. If it's over 400 the system dies though.What is important is the number of sleeping nginx and php-fpm processes. You use some public cloud. These thing are cheap and they promise the moon but in fact they are big pain in the ass. They lower the load and can handle more traffic in theory but with dedicated server it's hard to get many sleeping processes unless the server has problems with a hard drive or the hard drive controller. The reason for sleeping processes in clouds is bad I/O between the cloud nodes .MySQL on cloud is a big disaster it is the main reason to increase the average load CPU usage.As a %CPU as a process it can be over 1000% which is pretty crazy. They use the lan conectivity for everything and there's a lot of traffic generate d by the "mother" layer not your guest OS (CentOS,Debian etc). Sometimes even the back-up system of the cloud can cause the processes to "fall asleep". If you use PHP sessions that means even more sleeping processes. You can lower them if you use memcached serving the pages directly from the memory. That can be used if your pages are mainly "static".

Too many sleeping processes?


Heat Sink compound and older desktops and workstations

Question: This is my first question asked on SF, so be gentle kids.
As my desktops (approximately 110 or so) have begun to age and with my users resisting Windows 8, I've begun to notice an odd trend.  We are primarily an HP shop. So the desktops I am having the issues with are DX2200 and DX2300 series business desktops. (Yes yes, I know they are old, but they are still serviceable for what my users use the machines for.)  The users of some of the machines are complaining that the machines are very loud and/or "racing".  And they seem to be very slow opening up applications like Outlook and IE.  At first I went on the obvious hunt for viruses, but in not finding any and not being able to find a task that was consuming resources, I was stumped. Task man showed very little CPU usage, but the fans were running full out. Typically a sign that the CPU is under heavy load as these have variable speed fans controller by the motherboard.
In trying to solve the problem, I pulled the heatsink and fan assembly off the motherboard.  I discovered that the heat sink compound on many of these machines seems to have dried out.  I would describe the compound as flaky rather than smooth and gooey.  The fix for the issue is embarrassingly simple;  Simply clean and reapply some paste as recommended by the manufacturer.  I've had this happen in five desktops in the last few weeks.  Odd coincidence or simply a matter of finally noticing this?  Who knows. This resolves the issue with the CPU in all 5 machines.
While I had never considered this to be an issue, suddenly now I am beginning to wonder if this is unique to my facility.  We are a commercial printing facility and have chemicals and solvents in the building.  Or if this is simply a matter of maintenance on aging equipment.  I am inclined to believe this is an "old machine" issue.
I typically pull the cover off any machine I am working on just to physically inspect fans and heat sinks, but I now have added pulling the CPU heat sink and reapplying compound to any system work done on the bench.
Is anyone else having the same or similar issues with HP desktops/servers?
Comment: The first Pentium4/Pentium4HT processors were _notoriously_ hot, hence the very noisy fans with extremely "jumpy" fan speed adjustments at that time.
Comment: To clarify, you've identified the issue, and replacing the heat sink compound with fresh compound solves the CPU overheating problems and the resulting performance issues?
Comment: @Kaz, in this case, yes it solved the issue I was having.  But this was more of a "Am I the only one with this problem due to the physical enviornment or is this an HP issue?"  It looks to be an HP related issue as detailed by longneck below.
Comment: I have *never* seen an HP machine from that era that didn't eventually develop high heat and fan speed issues.
Comment: @MosheKatz, I have maybe 40 or so of these generation of HP machines still in service.  We've had 5 to date, but now that I am aware of the issue, I suspect on inspection, I will certainly find more I wasn't aware of.
Answer: I have experienced this exact same issue with similar Pentium 4 computers from HP. Within about 9 months we reapplied thermal compound to nearly all 80 or so of these PC's. They were all about 4 years old at the time.
After the 5th pc or so,  our purchasing department leaned on the hp sales guy and he bought us a case of thermal compound that came in little stickers. The funny part is he ordered 10 times too many so we had these stickers hanging around forever. I ended up doing all of my home PC's, too.
We ended up making a weekend day of servicing every pc of this model. Never had a problem again except for the occasional seized fan.
This was a typical office building. No chemical funny business going on nearby.
Comment: We've had a few seized fans as well, but they have been rare.  But it sounds like I am not the only one with issues with this gen of HP desktops, which is basically what I was curious about.
Answer: It could be that HP cheapskated when they applied thermal paste to those specific models - who knows after all these years. Like I said in the comment, those processors were notoriously ineffective and hot, which didn't get any better until the Core 2 series.
All your other questions are going to attract too many different opinions for a Q/A site, so I'd strip them out instead of having this question closed, and rather visit us at the Serverfault Chat room to discuss it.
Comment: I am inclined to think the same thing as far as HP goes.  Generally speaking most of these desktops are used by non power users.  So it is rare to see the CPUs pushed on these boxes other than on the occasions when large applications are opened.  (ie...Outlook).  Typically they run at the lowest speed and are pretty quiet.  I clarified the question as I am really only looking for a "is it only me or not" answer.
Answer: The thermal interface in the OEM cooling systems has not been "gooey" (even when brand new) for a long time now. But it does degrade over time. Those systems should be at least 7 years old now which is way more than the life span they were designed for - so it's hardly a design flaw/manufacturer's fault.
If you want to keep those running - just replace the thermal interface. But there's nothing to complain about
Comment: **Yes there is something to complain about!** 25 year old audio amplifiers still have good thermal paste and do not overheat any more than when they rolled off the assembly line. WTF?
Comment: No complaint, simply an observation.  I am very happy to not have to e-cycle these machines due to degraded performance.  Like you said, and I agree, they are well past their typical lifespan.  But if they meet the users expectations until MS EOLs the support on XP, I think doing a bit of maintenance is well worth the long term financial gains.  They really have been good little machines overall.
Comment: Odds are those 25 yo amplifiers were never commidity (read: cheap throw away) devices designed with the intention of only running 4-5 years at most before their MTBF.  Most of the machines I referred to in the original question have all had their Hard Drives replaced with SSDs (for performance and/or due to HD failure).  Had it not been for SSDs, I would have easily retired these machines years ago.  But the hassle for the users outweigh the benefits of switching to a new machine.  Not to mention the costs.


What test do I need to use for my dissertation, SPSS?

Question: My dissertation question is 'the comparison of cold water immersion and game ready on the alleviation of delayed onset muscle soreness in netball players'.
I have used 15 participants which were split:
5 received cold water immersion
5 received game ready
5 were part of a control group
Scores for delayed onset muscle soreness were given through a visual analogue scale at 5 different stages.. before exercise, immediately after exercise, 24hr post, 48hr post and 72hr post.
I am struggling on which test to perform as I havent used SPSS before
Answer: If you have data for all 15 participants at all 15 times, you will want to use a single-between-factor repeated measures ANOVA to test if there is a difference between the three treatment conditions.
Follow-up from comments below
Step 1:  From SPSS drop down menus:
      Analyze > General Linear Model > Repeated Measures...
Step 2:  Define the within-subject factors (the repeated things):
      • change Within-Subject Factor Name: to time
      • enter the number of levels: 5
      • click Add and then click Define
      • highlight the variables from the variable list for the repeated measures and click the arrow to move them to the Within-Subjects Variables Block
      • highlight the grouping variable from the variable list and click the arrow to move them to the Between-Subjects Factor(s) block
      • click OK
This should run the requested test.
Comment: Sorry, I really am struggling..
So if there are 3 different groups i do the single-factor-between-factor repeated measures anova?
I thought it was just a repeated measure ANOVA but this makes more sense, but I cant seem to find this option available on SPSS?
Comment: no worries...this is a bit tricky on SPSS. First, let's make sure you data is in the correct format in SPSS. You should have a row for each participant, a variable (column) indicating the group membership, and a separate set of columns for each of the time measurements. So, just to make sure, the data should have 6 columns and 15 rows. Let me know if that makes sense, and we can go from there.
Comment: Also, to clarify, single-factor-between means that individuals are assigned to different groups, and there is only one such set of groups (the factor)...though that factor can have different levels (or categories).  In your case, you have a single factor (treatment group) which has 3 distinct levels (cold H2O, game-ready & control).
Comment: I have correctly inputted data however have a few more columns due to height, weight and age.. All of that makes sense, could you please help me on what to do next?
Comment: Also, is the single-factor-between-factor repeated measures also known as a three way anova?
Comment: I've included a follow-up section in the answer above. Also, this is not a 3-way ANOVA (that is an ANOVA with three factors, where each subject is associated with only one level of each factor).
Comment: Sorry to sound stupid, but which ones do i move in the variables section and which ones go into the grouping variables? I think ive over thinked this so much and confused myself!
Comment: Ideally, you will have a grouping variable indicating which treatment (1=cold,2=game,3=control). This goes into the 2nd block. The first block should have 5 options waiting to be filled...these are the data for the 5 time collection points.
Comment: Thank you so much!! You have helped so much, cant thank you enough!
Comment: Really sorry to be such a pain.. I have ran the test and got the data back however im struggling to see which intervention has a bigger impact? Im not sure if this changes what test I need to do, because it isnt telling me the difference between each variable (as in, CWI, GR and CG) Im sorry im so confused!
Comment: @TaraWilson I'd suggest starting a new question and include your output to ask for assistance with that next.
Comment: Ok, thank you for your help, I have posted another question and hopefully i get a response :)


What does it mean for the hessian to have a value?

Question: The hessian matrix is the matrix formed by taking the second derivatives of some vector $X$.
$$\nabla^2 X = H$$
In determining whether a function at critical point is a minimum or maximum, we test to see whether the hessian is positive or negative.
Am I correct that to check whether the hessian is positive, we simply check whether all entries of the matrix are $> 0$?
Comment: No, positivity of the Hessian in this context means that all the eigenvalues are positive.
Comment: Three people have answered this or commented on it and so far I'm the only one who's up-voted the question. ${}\qquad{}$
Answer: (Note: The Hessian (as an operator) is not applied to "some vector $X$".  The Hessian is applied to a scalar function.)
I assume you're talking about the second derivative test.  In that case what you're looking for is whether the Hessian matrix is positive definite, negative definite, indefinite but nondegenerate, or none of the above.
Definition: A real-valued symmetric, square matrix is positive (negative) definite if all of its eigenvalues are positive (negative) real numbers.
The second derivative test states:

If your Hessian is positive definite at a critical point then that
point is a local minimum of your function.
If your Hessian is negative definite at a critical point then that
point is a local maximum of your function.
If your Hessian has positive and negative eigenvalues (but no
zeros) at a critical point, then that point is a saddle point.
If your matrix has a zero eigenvalue at a critical point then the test is inconclusive.

As some schools require multivariate calculus before linear algebra, if you don't understand the concept of an eigenvalue let me know and I'll give you an alternate criterion for determining positive/ negative definiteness.
Answer: Just look at the eigenvalues. If they are strictly positive, then you say that the Hessian (or matrix in general) is positive definite.


Como setar a hora de um "timestamp" para 23:59:59 no postgresql?

Question: Tenho em uma célula que contem apenas a data, no caso 2018-07-11, eu preciso fazer um select que vai trazer essa célula assim: 2018-07-11 23:59:59, é possivel fazer isso?
Comment: No caso vc quer que o select traga a data e a hora, mas na celula só existe a data? seria isso?
Comment: Qual o seu propósito ? Comparar datas ? Já pensou em fazer um CAST para  `DATE` no momento da comparação ?
Answer: As operações com datas no postgreSQL são faceis de implementar, como vemos na documentação
No seu caso basta fazer:
SELECT data, data + time '23:59:59'
FROM datas

Você pode ver isso funcionando no SQL Fiddle.


C# Null object Reference Error

Question: I am using a 3rd party API and new to programming so I need some guidance.
There is a class InStreamInfo which has properties
Comments
Dimention
Names
InStreamAdditionalInfo[]

InStreamAdditionalInfo[] class has properties defined as
ID
AddInfoDescription

I am creating a class object of InStreamInfo as
   InStreamInfo _info=new InStreamInfo ();
   _info.Comments="Test Comment";
   _info.Dimention= "200x300";
   _info.Names="Test Names 1";

While InStreamAdditionalInfo[] is defined as
InStreamAdditionalInfo[] _infoAdd= new InStreamAdditionalInfo[1];

_infoAdd[0].ID=12345;

But here I am getting an error

Object reference not set to an instance of an object.
Comment: Null references are always the same thing.  You are trying to access the property of an object whose value is null.  Check that link and it will show you every possible way that you can get that exception and how to repair it.
Comment: P.S.  If you instantiate an array of objects, it doesnt mean that the array is populated.
Comment: i saw the link but it has so many things i am confused can you tell me what i am doing wrong in my solution??
Comment: When you used the debugger what did you find?
Answer: You're creating an array with one position, but the array in this single position is null. You need to initialize _infoAdd[0]. Something like this
_infoAdd[0] = new InStreamAdditionalInfo();
_infoAdd[0].ID=12345;

Is not very common on C# to define the size of the collection. Unless you have a specific reason for this you could just use a collection that automatically increase its size when needed. This is an example
var _infoAdd= new List<InStreamAdditionalInfo>();
_infoAdd.Add(new InStreamAdditionalInfo { ID = 12345 });

Comment: Deja vu. It seems in consecutive days we both find ourselves here at [so] looking at yet another ObjectRefNotSetToAnInstance exception. btw I didn't downvote you but in future its probably best we close these questions down with a link to the duplicate (that has all the info for people to diagnose this very common exception).
Comment: @Jeremy Thompson: I think his confusion is about how a collection is initialized, don't think a general reference about this error helps. He believes that initializing the collection automatically initialize each posistion with a new instance.

C# Null object Reference Error


How can I add new components to a fieldset?

Question: I'd like to customize the webform everytime the user saves a webform node.  I'm using rules with a custom action that updates the webform when the user saves the node.  Looking at devel, I haven't been able to figure out what the proper key to specify a parent fieldset is.
In my action I have the following:
<code>for ($j = 1; $j <= 5; $j++) {
  $node->webform['components'][$i] = array(
    'nid' => $node->nid,
    'cid' => $i,
    'pid' => 0,
    'form_key' => "participant$j",
    'name' => "Participant",
    'type' => 'fieldset',
    'value' => '',
    'weight' => $j,
    'display' => array(
      'addmore' => $i,
    ),
    'extra' => array(
      'description' => 'Please provide the participant information listed below. Required items are denoted with an asterisk.',
      'title_display' => 0,
      'private' => 0,
      'collapsible' => 1,
      'conditional_component' => '',
      'conditional_operator' => '=',
      'conditional_values' => '',
    'mandatory' => 0,
    'page_num' => 1,
    ),
  );
  $i++;

  $node->webform['components'][$i] = array(
    'nid' => $node->nid,
    'cid' => $i,
    'pid' => 0,
    'form_key' => "first_name$j",
    'name' => 'First Name',
    'type' => 'textfield',
    'value' => '',

    'parent' => "participant$j",
    'extra' => array(
      'display' => array(
        'addmore' => $i,
      ),
      'title_display' => 'inline',
      'private' => 0,
      'disabled' => 0,
      'unique' => 0,
      'maxlength' => 60,
      'width' => '',
      'field_prefix' => '',
      'field_suffix' => '',
      'description' => '',
      'attributes' => array(),
      'conditional_component' => '',
      'conditional_operator' => '=',
      'conditional_values' => '',
    'mandatory' => 1,
    'page_num' => 1,
    ),
  );
  $i++;
...
</code>
Answer: It looks like setting the pid to the parent fieldset's cid achieves my goal.