text:
Q: How to store process IDs and kill them? I'm having trouble with dealing with background processes in my shell. I'm storing the pids in an array and then when I call 'jobs', it's supposed to iterate through the array and if the number is not 0 and if it is still alive, it prints, if not, it's supposed to remove the pid. I'm getting very inconsistent results. Can someone see what I'm doing wrong? Thanks
Result:
ben$ sleep 5 &
Ben: started job 30290
ben$ jobs
30290
ben$ jobs
30290
ben$ jobs
30290
ben$ kill 30290
ben$ kill 30290: No such process
jobs
ben$ jobs
ben$ sleep 4s &
Ben: started job 30547
ben$ jobs
30547
ben$ kill 30547
ben$ jobs
30547
ben$ jobs
30547
ben$

First file is main, and the second one is my functions file
/*
  Shell 1
*/

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <errno.h>
#include <unistd.h>
#include <sys/wait.h>
#include <stdbool.h>
#define DELIMS " \t\r\n"
int main (int argc, char *argv[]) {
  int ids[10];

  initializeArray(ids);

  while (1) {
      char line[100];
      char *temp;
      char *split[15];
      pid_t pid;
      bool background=false;

    printf("ben$ ");

    //if cmd-d, exit shell
   if(!fgets(line, sizeof(line), stdin)) {
      printf("\n");
      break;
   }

      line[strlen(line)-1]='\0';
      temp=strtok(line," ");

      if (strcmp(temp, "exit") == 0) {
        break;
      }
      else if (strcmp(temp, "cd") == 0) {
        char *arg = strtok(0, DELIMS);

        if (!arg) {
          fprintf(stderr, "cd missing argument.\n");
        }
        else {
          chdir(arg);
        }

      }
      else if (strcmp(temp, "jobs") == 0) {
        printJobs(ids);
        continue;
      }

      else {
      int i=0;
      while(temp != NULL) {
        split[i]=temp;
        temp=strtok(NULL," ");
        i++;
      }
      split[i] = NULL;
      if(strcmp(split[i-1], "&")==0) {
        // printf("should do in background");
        split[i-1]='\0';
        background=true;
      }

      char *args[i];
      int j;
      for(j=0; j < i; j++){
        args[j]=split[j];
      }

      pid=fork();

      if(pid==0) {
        if(background) {
                  fclose(stdin);
                  fopen("/dev/null","r");
        }
        execvp(args[0], args);
        printf("This should not happen\n");
      }
      else {
        if(!background) {
           // printf("Not in background\n");
           wait(&pid);
        }
        else {
           printf("Ben: started job %d\n",pid);
           insertPid(ids,pid);
           background=false;
        }
     }
    }

  }
  return 0;
}

#include <stdio.h>
#include <stdlib.h>
#include <string.h>

void initializeArray(int ids[]);
void insertPid(int ids[],int pid);
void removePid(int ids[],int pid);
void printJobs(int ids[]);

void initializeArray(int ids[]) {
    int i;
    for(i=0;i<10;i++) {
        ids[i]=0;
    }

}

void insertPid(int ids[],int pid) {
    // printf("inserting\n");
    int i=0;

    while(i<10) {
        if(ids[i]==0) {
            ids[i]=pid;
            return;
        }
        i++;
    }
    printf("insert into list error");
    return;
}
void removePid(int ids[],int index) {
    // printf("removing %d\n",pid );
       ids[index]=0;
        return;
}
void printJobs(int ids[]) {
    // printf("printing\n");
    int i;
    int pid;
    for(i=0;i<10;i++) {

        if(ids[i] != 0) {
            // printf("job value %d",ids[i]);
            pid=ids[i];
            if(kill(pid,0) == 0) {
                printf("%d\n",pid);
            }
            else{
                removePid(ids,i);
            }
        }
    }
}

A: How do you know if your (background) jobs have died?  You wait on your foreground job - so you know when they have completed - but you don't handle the background jobs.  Whether you kill the children or they eventually expire on their own (e.g. sleep runs out in the example case) you won't know it.  That is what you are seeing in your output listing too.
One way to approach this is to set up a signal handler for SIGCHLD and waitpid on them when they die.  Then update your jobs array.  Or some variation thereof.


text:
Q: Mongodb remove array with id .Net I have collections student and class.
Class contains an array of students. Whenever a student is edited it will also be edited in all the classes that the student is in.
So when a student is deleted I also want it to be deleted from all the classes it is in.
Right now I am having to pass the whole student to pull from the class
var query = Query.EQ("Students._id", idOfStudent);
var update = Update<Class>.Pull(x => x.Students, studentToRemove);

Is there a better way to pull where I can just pass in the student id for that student?
EDITED
public class Student
{
   [BsonId]
   public Guid Id {get; set;}
   public string Name {get; set;}
}

public class Class
{
   [BsonId]
   public Guid Id {get; set;}
   public string Grade {get; set;}
   public List<Student> Students {get; set;}
}

Then my class collection would look like
{
    "_id" : NUUID("..."),
    "Grade" : "5th",
    "Students" : [
           {
              "_id" : NUUID("..."),
               "Name" : "Chris"
           },
            {
              "_id" : NUUID("..."),
               "Name" : "Bob"
           }
}

And my student collection would look like
  {
    "_id" : NUUID("..."),
    "Name" : "Chris"
  }

When someone deletes Student 'Chris' they supply an id which will be used to find the student and delete it, but I also want to take that id and pull that student from all the Classes they are in.

A: Yes, you can, using the unique identifier in your student:
var joe = new Student { Name = "Joe", Id = Guid.NewGuid() };
/// ....
var query = Query<Class>.EQ(p => p.Id, doc.Id);
var update = Update<Class>.Pull(r => r.Students, p => p.EQ(q => q.Id, joe.Id));

Hints:

*

*Remember that GUIDs provide bad data locality - that can be a problem or it can be advantageous, but most data roughly has creation-time locality, so ObjectId is often a better bet.

*I'd suggest you use the same coding style - either expression based, or string based, but your query uses the string-based notation while the update uses an expression

redpajama_set_name: RedPajamaStackExchange


text:
Q: material md-select with reactive formcontrol is not updating values I am building multi-step form using md-tabs from @angular/material.

*

*Angular 4.2.x

*Material 2.0.0-beta.10

*Reactive Form Module

My Template :
<form novalidate [formGroup]="crForm">
  <md-tab-group class="tab-group" dynamicHeight="true [(selectedIndex)]="crFormSelectedTab" >
    <md-tab label="Provide basic info">

          <md-form-field fxFlex="30%" fxFlex.xs="100%">
            <input mdInput placeholder="Title" formControlName="title"/>
          </md-form-field>

          <md-select placeholder="Change request Type" fxFlex="30%" fxFlex.xs="100%" formControlName="type">
            <md-option [value]="sample1">
              request1
            </md-option>
            <md-option [value]="sample2">
              request2
            </md-option>
            <md-option [value]="sample3">
              request3
            </md-option>
          </md-select>
          <md-select placeholder="Analysis priority" fxFlex="30%" fxFlex.xs="100%" formControlName="priority">
            <md-option [value]="sample1">
              request1
            </md-option>
            <md-option [value]="sample2">
              request2
            </md-option>
            <md-option [value]="sample3">
              request3
            </md-option>
          </md-select>

          <md-form-field fxFlex="30%" fxFlex.xs="100%">
            <input mdInput placeholder="Change Specialist 1" formControlName="CS1" />
            <md-hint align="start">WOSO / wos / 00310140 </md-
  hint>
          </md-form-field>
          Is an upgrade required?
          <md-radio-group fxFlex="29%" fxFlex.xs="80%">
            <md-radio-button value="yes">yes</md-radio-button>
            <md-radio-button value="no">no</md-radio-button>
          </md-radio-group>

    </md-tab>
    <md-tab label="select trigger">

        <md-select multiple placeholder="PBS ID" fxFlex="30%" fxFlex.xs="100%" formControlName="PBSID">
          <md-option [value]="sample1">
            request1
          </md-option>
          <md-option [value]="sample2">
            request2
          </md-option>
          <md-option [value]="sample3">
            request3
          </md-option>
        </md-select>
        <md-select placeholder="PCCSTRAIM ID" fxFlex="30%" fxFlex.xs="100%">
          <md-option [value]="t1">
            TYPE1
          </md-option>
          <md-option [value]="t2">
            TYPE2
          </md-option>
          <md-option [value]="t2">
            TYPE3
          </md-option>
        </md-select>

    </md-tab>
    <md-tab label="provide details">

    </md-tab>
    <md-tab label="impact analysis">

        <md-select placeholder="Impacted product baseline" fxFlex="30%"
 fxFlex.xs="100%" formControlName="impactedItems">
          <md-option [value]="sample1">
            request1
          </md-option>
          <md-option [value]="sample2">
            request2
          </md-option>
          <md-option [value]="sample3">
            request3
          </md-option>
        </md-select>

    </md-tab>
  </md-tab-group>
</form>

Component :
import { Component, OnInit } from '@angular/core';
import { LocalHttpClientService } from '../../shared/local-http-
client.service';
import {  URLSearchParams } from '@angular/http';
import { FormBuilder, FormGroup, Validators } from '@angular/forms';
@Component({
  selector: 'app-change-request-add',
  templateUrl: './change-request-add.component.html',
  styleUrls: ['./change-request-add.component.css']
})
export class ChangeRequestAddComponent implements OnInit {
  crFormSelectedTab: number;
  crId: number;
  crForm: FormGroup;
  constructor(private LHCP: LocalHttpClientService, private fb: FormBuilder) {
    this.crFormSelectedTab = 0;
  }
  ngOnInit() {
    this.crForm = this.fb.group({
      title: ['', [Validators.required, Validators.minLength(3)] ],
      type: ['', [Validators.required]],
      impactedItems: ['',[Validators.required]],
      PBSID: ['', [Validators.required]],
      CS1: ['', [Validators.required]],
      priority: ['', [Validators.required]]
    });
  }
}

There are no errors regarding module imports as i included all the required.
problem 1:
 Formcontrol for input values are working but for md-select value is not binding.
problem 2:
most weird part is "type" formcontrol inside formgroup  is being deleted on selecting one item of select box.
I have tested above statement with following
{{ crForm.value|json }}

A: Both of your two question is caused by incorrect way of binding values to md-option as [value]="sample1".
[] in angular is property binding operator, angular will look for value of variable sample1 from your component. Here you didn't define those sample1, sample2 as public variables in your component, so your md-option's value will be undefined.
Just guess you may want to bind it as below ways:
value="sample1"
[value]="'sample1'"

So for your questions:

Formcontrol for input values are working but for md-select value is not binding.

Your md-option don't have real value, so there will be no matched option been setted to selected status.

most weird part is "type" formcontrol inside formgroup is being deleted on selecting one item of select box.

When an formControl's value is changed to undefined, it'll be removed from form.value set.


text: Q: How can I use refresh token with retrofit 2 to get new access token I am developing android app using kotlin and I want to know if there is a best practice to fetch new token after the current token expires. I did some research but could not find any standard way of doing it. If anyone can suggest me a way about using refresh token with retrofit 2 would be nice.


text:
Q: TextBox TextChanged event does not fire when Visible = False? I have a textbox bound to a datasource. The textbox's TextChanged event updates another textbox.
The problem is, I do not want the first textbox to show, so I set its Visible property to false.
However, now the TextChanged event does not fire!
I can work around it by setting Visible=True, Left=-100000 on form load, but I'd like a proper solution.
Can anyone offer an explanation?

A: Set your textbox.Visible = false in the FormLoad event instead of in the designer. It has to do with handle creation. If the textbox is not visible during construction, then the handle is not created. If the textbox is made invisible after construction, then the handle will have been created and events will occur.
See this discussion on MSDN.

A: An alternative solution to the accepted answer is to set up the TextChanged listener on Loaded, this works for me just the same (in Silverlight at least) and keeps the designer view as it should be.

A: What type of datasource is it? It might have an event that you can use directly instead of using a textbox to listen for an update.

A: If Visible is equal to false then the Control is not rendered. Therefore it will be unable to fire an event.
Instead, set the style to display:none. You can set/unset this programmatically using the Attributes collection:
MyTextBox.Attributes.Add("style", "display: none");


text:
Q: Support combinatorics? How can I get spotlight to recognise expressions like 8C5 or 7P4?
I want to do combinations and permutations with spotlight.

A: After proper transformations you can calculate at least simple combinations and permutations in Spotlight:
7P4=7!/(7-4)!=7!/3!. Entered in Spotlight as 7!/3! it will give you a proper result: 840.
C(8,5)=8!/5!(8-5)!=8!/5!3!. Entered in Spotlight as 8!/5!3! it will give you a proper result: 56.
For info on other advanced functions besides Factorial which Spotlight can handle, see this page

According to Google Search a WolframAlpha Spotlight plug-in for Flashlight (a Spotlight extender - link in the other answer) which should be capable of doing these kind of calculations once existed but I can't actually find it or it's gone.

With Google Chrome installed you can use a work-around and add the Wolfram | Alpha extension which supports expressions like in your question in the extra search bar:

A: There is no easy way to do this.
Spotlight has access to doing calculations with the built-in Calculator.app, so you can put in some simple arithmetic expressions. However, this app is not able to compute combinations/permutations.
There seems to be something you can install called Flashlight (http://flashlight.nateparrott.com) that will let you write custom plugins for Spotlight, so maybe that is a solution (I have never used it, so I don't know how easy or difficult it would be).


text:
Q: Using react-native-draw-on-screen package, missing Controls module? I'm trying to build a react native app with a drawing feature and I came across this package: https://www.npmjs.com/package/react-native-draw-on-screen
This package was also mentioned in this post:
How to draw on the screen with React Native?
It seems that we have to import a module called 'Controls' based on the example, but I'm not sure if that code is provided in the package.
I also tried looking up if react has anything related to handleColorChange or handleBrushSizeChange, but that seems to be specific to the Controls module.
Is there something I could write in place of this module?
I'd really appreciate any help on this!
Below is the example code that the package provides:
import React from 'react';
import { StyleSheet, View, SafeAreaView } from 'react-native';
import RNDrawOnScreen from 'react-native-draw-on-screen';
import Controls from './Controls';

export default class App extends React.Component {
  state = {
    color: 'black',
    strokeWidth: 10,
  };

  changeColor = (color) => {
    this.setState({ color });
  };

  changeBrushSize = (strokeWidth) => {
    this.setState({ strokeWidth });
  };

  undo = () => {
    this.RNDraw.undo();
  };

  clear = () => {
    this.RNDraw.clear();
  };

  render() {
    return (
      <SafeAreaView style={{ flex: 1 }}>
        <Controls
          handleColorChange={this.changeColor}
          handleBrushSizeChange={this.changeBrushSize}
          selectedColor={this.state.color}
          selectedStrokeWidth={this.state.strokeWidth}
          handleUndo={this.undo}
          handleClear={this.clear}
        />
        <View
          style={{
            flex: 1,
            flexGrow: 1,
            border: 'solid',
            borderWidth: 2,
            borderColor: '#ccc',
          }}
        >
          <RNDrawOnScreen
            penColor={this.state.color}
            strokeWidth={this.state.strokeWidth}
            ref={(r) => (this.RNDraw = r)}
          />
        </View>
      </SafeAreaView>
    );
  }
}

P.S. this is my first post on stackoverflow, would appreciate any feedback on asking good questions as well!


text:
Q: SQLite 'INSERT OR REPLACE INTO' incorrect behaviour I'm using SQLite to store an id, uuid, value and a caught value.
I create the table with this command:
CREATE TABLE IF NOT EXISTS statz_fish_caught
('id' INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL,
 'uuid' TEXT NOT NULL,
 'value' INTEGER NOT NULL,
 'caught' TEXT NOT NULL);

I use this command to insert (or replace) rows:
INSERT OR REPLACE INTO statz_fish_caught (uuid,value,caught)
VALUES ('uuid comes here', a number here, 'a certain string').

Let's say you have this data in the table:
http://pasteboard.co/gofap3y.png
This data would imply that UUID1 caught a total of 9 (1+5+3) fishes. 1 of fish type 1, 5 of fish type 2 and 3 of fish type 3. UUID2 has only caught 10 fishes of fish type 1. Now let's imagine UUID1 catches a new fish type: fish type 4. The database should create a new row with an auto incremented value of id 5, with uuid as 'uuid1', value=1 and caught=fish type 4.
Now let's also imagine UUID catches another fish of fish type 3. The row of uuid1 with fish type 3 (it has id 3) should be updated to represent value 4, like this:
http://pasteboard.co/goBZatx.png
Is this possible, if yes, how?

A: You are using an INTEGER AUTOINCREMENT PRIMARY KEY, and you don't have any other UNIQUE field in your table: this means that it is impossible to have a conflict between the existing rows and the one you are trying to add, therefore there will be no REPLACE
You should change the definition of your table like this:
CREATE TABLE IF NOT EXISTS statz_fish_caught
('id' INTEGER PRIMARY KEY NOT NULL,
 'uuid' TEXT NOT NULL,
 'value' INTEGER NOT NULL,
 'caught' TEXT NOT NULL);

Be aware that, by changing this, you have to manually put the id value when you add the rows, since it's not managed by the DBMS anymore.
Edit: Here you can find a working example; notice how the value of the primary key hasn't changed.
Edit #2: As suggested by ishmaelMakitla, putting UNIQUE for the UUID field should do the trick; I've updated my answer accordingly.
CREATE TABLE IF NOT EXISTS statz_fish_caught
('id' INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL,
 'uuid' TEXT NOT NULL UNIQUE,
 'value' INTEGER NOT NULL,
 'caught' TEXT NOT NULL);

A warning: as stated in the SQLite documentation,

The AUTOINCREMENT keyword imposes extra CPU, memory, disk space, and disk I/O overhead and should be avoided if not strictly needed. It is usually not needed.

Plus, as you can see in this example, the id of the updated row has changed, which is something that I strongly recommand to avoid.
Edit #3
It took me a while, but this example should do what you want.
The query you have to use is something like this (6 is the caught fishes you want to add):
INSERT OR REPLACE INTO statz_fish_caught (uuid,value,caught)
VALUES (
     -- (select `id` from statz_fish_caught where uuid = 'uu1'),
     'uu1',
     (select `value` from statz_fish_caught where uuid = 'uu1') + 6,
     (select `caught` from  statz_fish_caught where uuid = 'uu1')
);

Note that if you want to keep the current value of the id field for the updating row, you have to uncomment the first line of the values and add the id field in the list of columns of the statement.

A: In addition to what Cynical said, you should set UUID to UNIQUE - this way, the row with a matching UUID will be replaced. So the table should be modified as follows:
CREATE TABLE `statz_fish_caught` (
`id`    INTEGER NOT NULL,
`uuid`  TEXT NOT NULL UNIQUE,
`value` INTEGER NOT NULL,
`caught`    TEXT NOT NULL,
PRIMARY KEY(id)
);

I have tested this by doing the following:
INSERT OR REPLACE INTO statz_fish_caught
(uuid,value,caught) VALUES (hex(randomblob(16)), 1, 'caught-1 ');

Then I executed the following query string (note, I used the UUID generated by   hex(randomblob(16) in the previous query). So by running :
INSERT OR REPLACE INTO statz_fish_caught (uuid,value,caught) VALUES ('uuid-of-row-to-update', 2, 'caught-1-updated');


text:
Q: Prevent laravel morphMany casting id to integer Im developing an app, where the primary key of a Customers model is a brazilian document number, saved as string, with fixed length of 11 numbers. The customer has a MorphMany relationship to an "addressable" entity.
The problem is: when saving the address to the customer with doc number starting with 0 (zeros), they get dropped when the db casts it to integer.
For example: If the document number is 00012345678, the value that gets saved is 12345678
My question is: How to prevent addressable_id value of being cast from string to integer?
The closest solution I've got is to manually create the addressable_id and addressable_type in my addresses table. Would this be a good solution?

A: Since I've got no other answers, I kept my own solution:
After looking at the source code of the morphs function I just manually added the columns and the index to my migration file:
    $table->string("addressable_type"); // the owner class of the address
    $table->string("addressable_id"); // forces owner id to be string
    $table->index(["addressable_type", "addressable_id"], null); // creates index

So it does not matter if the id is the customer document number (string - like 00012345678) or the id of another table (integer - like 0123 which will be cast to 123)


text:
Q: Adding Image to ListView - SQL Server database - image doesn't appear I'm working on a dynamic listview from SQL Server 2000 database, and I need to add image on it. I already added ImageList control to my form, and set the ListView property to LargeIcon, SmallImageList as the ImageList.
I do not know how to add image on the listview. Here is my code and I don't know what's wrong with it, though it shows the data from database, only the image is not appearing:
Public Sub PopulateListView_Images(ByVal lv As ListView, ByVal cmd As SqlCommand, ByVal myImageList As ImageList)
    Dim da As New SqlDataAdapter
    Dim ds As New DataSet

    ds.Reset()
    da = New SqlDataAdapter(cmd)
    da.Fill(ds)
    'Fill Method
    lv.Columns.Clear()
    lv.Items.Clear()

    lv.SmallImageList = myImageList

    'Fill Listview
    Dim c As DataColumn
    For Each c In ds.Tables(0).Columns
        'adding names of columns as Listview columns
        Dim h As New ColumnHeader
        h.Text = c.ColumnName
        h.Width = 60
        lv.Columns.Add(h)
    Next
    Dim dt As DataTable = ds.Tables(0)
    Dim str(ds.Tables(0).Columns.Count) As String

    'adding Datarows as listview Grids
    Dim rr As DataRow
    For Each rr In dt.Rows
        For col As Integer = 0 To ds.Tables(0).Columns.Count - 1
            str(col) = rr(col).ToString()
        Next
        Dim ii As New ListViewItem(str)
        lv.Items.Add(ii)
        'showing the number of records still added
    Next
End Sub

In this code, only the data is showing but no image. I tried adding :
lv.Items(0).ImageKey = 0


text:
Q: python scatterplot annotation I am working on a small scatterplot project and it's coming together as well as could be but i want to add the name column to the corresponding dots in the scatterplot. Can someone help me because i can't seem to figure it out.
Thanks
import pandas as pd
import matplotlib.pyplot as plt

df = pd.read_csv("moneynuts.csv", index_col=0)
columns = df.columns

def clean_stringy_number(num: str) -> str:

    if num == "-":
        return "0"

    num = num.replace(",", "")

    return num

df.dropna(subset=['Gls'], inplace=True)

df.dropna(subset=['xG'], inplace=True)
#df.sort_values(by=['Gls', 'xG'])

df["Gls"] = df["Gls"].apply(clean_stringy_number)

df["Gls"] = df["Gls"].apply(int)
df["xG"] = df["xG"].apply(clean_stringy_number)
df["xG"] = df["xG"].apply(float)

for index, row in df.iterrows():
    if (row["Gls"] == "-" or row["Gls"] == "0"):

        df['Gls'].dtypes
        if (row["xG"] == "-" or row["xG"] == "0"):

            continue
        continue
    print (row["Name"], " average goals of ", row["Gls"], " With an xG of ", row["xG"])

    try:
        gls = float(row["Gls"].replace(",", "."))
        xG = float(row["xG"].replace(",", "."))
    except:
        print("Unknown char")

df["xG"] = df["xG"] / 100

sp = df.plot.scatter(x='Gls',
                     y='xG')
x_values = df["Gls"].astype(int)
plt.xticks(range(x_values.min(), x_values.max()+1))
plt.show()


text:
Q: Writing Test Case using Mocha and Chai for a function with response.send( ) I'm doing testing in node.js for the first time. I've created a simple program below. An html form has two fields, name and age. When a user submits the form, the age is checked in certificate function inside 'ageVerification.js' for it should be more than 18. If age is less than 18, null is returned otherwise some random number. Had the same getAuth function thrown error, then i would test it using
expect(auth.getAuth.bind(this,req,{})).to.throw('whatever thrown')
but if the function is just ended with res.send("some string"), then how to test the function. Thanks in advance.
  **code to test**
    const certificate=require('./ageVerification')
    module.exports.getAuth=function(req,res){
    if(certificate.certificate(req.body.ageText)!=null &&
            req.body.uName=='prateek'){
            res.write("Hello Prateek")
            return res.end()
        }

        if(certificate.certificate(req.body.ageText)!=null &&
            req.body.uName!='prateek')
            return res.send("You need to register first")

        if(certificate.certificate(req.body.ageText)==null){
             res.write("You are not of required age")
             return res.end()
        }
   }

 **test case**
const certificate=require('../ageVerification')
const auth=require('../controller')
const chai=require('chai')
const expect=require('chai').expect;
describe("Age field is null",function(){
    it("name is correct",function(done){
        const req={
            body:{
                ageText:null,
                uName:'prateek'
            }
        }
         expect(auth.getAuth.bind(this,req,{})).[I'm stuck here ???]

    })
})

A: You need to use sinonjs to make stubs for res.send, res.write and res.end methods and assert them have been called or not to check the code logic.
E.g.
controller.js:
const certificate = require('./certificate');

module.exports.getAuth = function(req, res) {
  if (certificate.certificate(req.body.ageText) != null && req.body.uName == 'prateek') {
    res.write('Hello Prateek');
    return res.end();
  }

  if (certificate.certificate(req.body.ageText) != null && req.body.uName != 'prateek')
    return res.send('You need to register first');

  if (certificate.certificate(req.body.ageText) == null) {
    res.write('You are not of required age');
    return res.end();
  }
};

certificate.js:
exports.certificate = function(age) {
  return age;
};

controller.test.js:
const auth = require('./controller');
const sinon = require('sinon');

describe('61943894', function() {
  afterEach(() => {
    sinon.restore();
  });
  it('should return required age message', function() {
    const mReq = {
      body: {
        ageText: null,
        uName: 'prateek',
      },
    };
    const mRes = {
      write: sinon.stub().returnsThis(),
      send: sinon.stub().returnsThis(),
      end: sinon.stub(),
    };
    auth.getAuth(mReq, mRes);
    sinon.assert.calledOnceWithExactly(mRes.write, 'You are not of required age');
    sinon.assert.calledOnce(mRes.end);
  });

  it('should say hello', () => {
    const mReq = {
      body: {
        ageText: 29,
        uName: 'prateek',
      },
    };
    const mRes = {
      write: sinon.stub().returnsThis(),
      send: sinon.stub().returnsThis(),
      end: sinon.stub(),
    };
    auth.getAuth(mReq, mRes);
    sinon.assert.calledOnceWithExactly(mRes.write, 'Hello Prateek');
    sinon.assert.calledOnce(mRes.end);
  });

  it('should return register message', () => {
    const mReq = {
      body: {
        ageText: 29,
        uName: '',
      },
    };
    const mRes = {
      write: sinon.stub().returnsThis(),
      send: sinon.stub().returnsThis(),
      end: sinon.stub(),
    };
    auth.getAuth(mReq, mRes);
    sinon.assert.calledOnceWithExactly(mRes.send, 'You need to register first');
  });
});

unit test results with coverage report:
  61943894
    ✓ should return required age message
    ✓ should say hello
    ✓ should return register message

  3 passing (34ms)

----------------|---------|----------|---------|---------|-------------------
File            | % Stmts | % Branch | % Funcs | % Lines | Uncovered Line #s
----------------|---------|----------|---------|---------|-------------------
All files       |     100 |       90 |     100 |     100 |
 certificate.js |     100 |      100 |     100 |     100 |
 controller.js  |     100 |       90 |     100 |     100 | 12
----------------|---------|----------|---------|---------|-------------------


text:
Q: unable to create a heat map with ggplot2  dput(head(tt,500))
structure(list(DATE = structure(c(15744, 15744, 15744, 15744,
15744, 15744, 15744, 15744, 15744, 15744, 15744, 15744, 15744,
15744, 15744, 15744, 15744, 15744, 15744, 15744, 15744, 15744,
15744, 15744, 15744, 15744, 15744, 15744, 15744, 15744, 15744,
15744, 15744, 15744, 15744, 15744, 15744, 15744, 15744, 15744,
15744, 15744, 15744, 15744, 15744, 15744, 15744, 15744, 15744,
15744, 15744, 15744, 15744, 15744, 15744, 15744, 15744, 15744,
15744, 15744, 15744, 15744, 15744, 15744, 15744, 15744, 15744,
15744, 15744, 15744, 15744, 15744, 15744, 15744, 15744, 15744,
15745, 15745, 15745, 15745, 15745, 15745, 15745, 15745, 15745,
15745, 15745, 15745, 15745, 15745, 15745, 15745, 15745, 15745,
15745, 15745, 15745, 15745, 15745, 15745, 15745, 15745, 15745,
15745, 15745, 15745, 15745, 15745, 15745, 15745, 15745, 15745,
15745, 15745, 15745, 15745, 15745, 15745, 15745, 15745, 15745,
15745, 15745, 15745, 15745, 15745, 15745, 15745, 15745, 15745,
15745, 15745, 15745, 15745, 15745, 15745, 15745, 15745, 15745,
15745, 15745, 15745, 15745, 15745, 15745, 15745, 15745, 15745,
15745, 15745, 15745, 15745, 15745, 15745, 15745, 15745, 15745,
15745, 15745, 15745, 15745, 15745, 15745, 15745, 15745, 15745,
15745, 15745, 15745, 15745, 15745, 15745, 15746, 15746, 15746,
15746, 15746, 15746, 15746, 15746, 15746, 15746, 15746, 15746,
15746, 15746, 15746, 15746, 15746, 15746, 15746, 15746, 15746,
15746, 15746, 15746, 15746, 15746, 15746, 15746, 15746, 15746,
15746, 15746, 15746, 15746, 15746, 15746, 15746, 15746, 15746,
15746, 15746, 15746, 15746, 15746, 15746, 15746, 15746, 15746,
15746, 15746, 15746, 15746, 15746, 15746, 15746, 15746, 15746,
15746, 15746, 15746, 15746, 15746, 15746, 15746, 15746, 15746,
15746, 15746, 15746, 15746, 15746, 15746, 15746, 15746, 15746,
15746, 15746, 15746, 15746, 15746, 15746, 15746, 15746, 15746,
15746, 15746, 15746, 15746, 15746, 15746, 15746, 15746, 15746,
15746, 15746, 15746, 15747, 15747, 15747, 15747, 15747, 15747,
15747, 15747, 15747, 15747, 15747, 15747, 15747, 15747, 15747,
15747, 15747, 15747, 15747, 15747, 15747, 15747, 15747, 15747,
15747, 15747, 15747, 15747, 15747, 15747, 15747, 15747, 15747,
15747, 15747, 15747, 15747, 15747, 15747, 15747, 15747, 15747,
15747, 15747, 15747, 15747, 15747, 15747, 15747, 15747, 15747,
15747, 15747, 15747, 15747, 15747, 15747, 15747, 15747, 15747,
15747, 15747, 15747, 15747, 15747, 15747, 15747, 15747, 15747,
15747, 15747, 15747, 15747, 15747, 15747, 15747, 15747, 15747,
15747, 15747, 15747, 15747, 15747, 15747, 15747, 15747, 15747,
15747, 15747, 15747, 15747, 15747, 15747, 15747, 15747, 15747,
15748, 15748, 15748, 15748, 15748, 15748, 15748, 15748, 15748,
15748, 15748, 15748, 15748, 15748, 15748, 15748, 15748, 15748,
15748, 15748, 15748, 15748, 15748, 15748, 15748, 15748, 15748,
15748, 15748, 15748, 15748, 15748, 15748, 15748, 15748, 15748,
15748, 15748, 15748, 15748, 15748, 15748, 15748, 15748, 15748,
15748, 15748, 15748, 15748, 15748, 15748, 15748, 15748, 15748,
15748, 15748, 15748, 15748, 15748, 15748, 15748, 15748, 15748,
15748, 15748, 15748, 15748, 15748, 15748, 15748, 15748, 15748,
15748, 15748, 15748, 15748, 15748, 15748, 15748, 15748, 15748,
15748, 15748, 15748, 15748, 15748, 15748, 15748, 15748, 15748,
15748, 15748, 15748, 15748, 15748, 15748, 15749, 15749, 15749,
15749, 15749, 15749, 15749, 15749, 15749, 15749, 15749, 15749,
15749, 15749, 15749, 15749, 15749, 15749, 15749, 15749, 15749,
15749, 15749, 15749, 15749, 15749, 15749, 15749, 15749, 15749,
15749, 15749, 15749, 15749, 15749, 15749, 15749, 15749, 15749,
15749), class = "Date"), TIME1 = structure(c(0.0100694444444444,
0.0204976851851852, 0.0309143518518519, 0.0413310185185185, 0.0517476851851852,
0.0621643518518519, 0.0725810185185185, 0.0830092592592593, 0.0934259259259259,
0.103842592592593, 0.114259259259259, 0.124675925925926, 0.135092592592593,
0.145520833333333, 0.1559375, 0.166354166666667, 0.176770833333333,
0.1871875, 0.197604166666667, 0.208032407407407, 0.218449074074074,
0.228865740740741, 0.239282407407407, 0.249699074074074, 0.260115740740741,
0.270532407407407, 0.280960648148148, 0.291377314814815, 0.301793981481481,
0.312210648148148, 0.322627314814815, 0.333043981481481, 0.343460648148148,
0.353877314814815, 0.364293981481481, 0.374722222222222, 0.385138888888889,
0.395555555555556, 0.405972222222222, 0.416388888888889, 0.426805555555556,
0.437222222222222, 0.447650462962963, 0.45806712962963, 0.468483796296296,
0.478900462962963, 0.48931712962963, 0.499733796296296, 0.510162037037037,
0.520578703703704, 0.53099537037037, 0.541412037037037, 0.551828703703704,
0.56224537037037, 0.572673611111111, 0.583090277777778, 0.593506944444444,
0.603923611111111, 0.614340277777778, 0.624756944444444, 0.635185185185185,
0.645601851851852, 0.656018518518519, 0.666435185185185, 0.676851851851852,
0.687268518518519, 0.697685185185185, 0.708113425925926, 0.718530092592593,
0.728946759259259, 0.739363425925926, 0.749780092592593, 0.760196759259259,
0.770613425925926, 0.781030092592593, 0.791458333333333, 0.801875,
0.812291666666667, 0.822708333333333, 0.833125, 0.843541666666667,
0.853958333333333, 0.864375, 0.874803240740741, 0.885219907407407,
0.895636574074074, 0.906053240740741, 0.916469907407407, 0.926886574074074,
0.937303240740741, 0.947731481481481, 0.958148148148148, 0.968564814814815,
0.978981481481481, 0.989398148148148, 0.999814814814815, 0.0100694444444444,
0.0204861111111111, 0.0309027777777778, 0.0413310185185185, 0.0517476851851852,
0.0621643518518519, 0.0725810185185185, 0.0829976851851852, 0.0934143518518518,
0.103831018518519, 0.114259259259259, 0.124675925925926, 0.135092592592593,
0.145509259259259, 0.155925925925926, 0.166342592592593, 0.176759259259259,
0.1871875, 0.197604166666667, 0.208020833333333, 0.2184375, 0.228854166666667,
0.239270833333333, 0.2496875, 0.260115740740741, 0.270532407407407,
0.280949074074074, 0.291365740740741, 0.301782407407407, 0.312199074074074,
0.322615740740741, 0.333032407407407, 0.343460648148148, 0.353877314814815,
0.364293981481481, 0.374710648148148, 0.385127314814815, 0.395543981481481,
0.405960648148148, 0.416377314814815, 0.426793981481481, 0.437222222222222,
0.447638888888889, 0.458055555555556, 0.468472222222222, 0.478888888888889,
0.489305555555556, 0.499722222222222, 0.510138888888889, 0.520555555555556,
0.530983796296296, 0.541400462962963, 0.55181712962963, 0.562233796296296,
0.572650462962963, 0.58306712962963, 0.593483796296296, 0.603900462962963,
0.61431712962963, 0.624733796296296, 0.635162037037037, 0.645578703703704,
0.65599537037037, 0.666412037037037, 0.676828703703704, 0.68724537037037,
0.697662037037037, 0.708078703703704, 0.71849537037037, 0.728912037037037,
0.739340277777778, 0.749756944444444, 0.760173611111111, 0.770590277777778,
0.781006944444444, 0.791423611111111, 0.801840277777778, 0.812256944444444,
0.822673611111111, 0.833101851851852, 0.843518518518519, 0.853935185185185,
0.864351851851852, 0.874768518518519, 0.885185185185185, 0.895601851851852,
0.906018518518519, 0.916446759259259, 0.926863425925926, 0.937280092592593,
0.947696759259259, 0.958113425925926, 0.968530092592593, 0.978946759259259,
0.989363425925926, 0.999780092592593, 0.0100694444444444, 0.0204861111111111,
0.0309143518518519, 0.0413310185185185, 0.0517476851851852, 0.0621643518518519,
0.0725810185185185, 0.0829976851851852, 0.0934259259259259, 0.103842592592593,
0.114259259259259, 0.124675925925926, 0.135092592592593, 0.145509259259259,
0.1559375, 0.166354166666667, 0.176770833333333, 0.1871875, 0.197604166666667,
0.208020833333333, 0.218449074074074, 0.228865740740741, 0.239282407407407,
0.249699074074074, 0.260115740740741, 0.270532407407407, 0.280949074074074,
0.291377314814815, 0.301793981481481, 0.312210648148148, 0.322627314814815,
0.333043981481481, 0.343460648148148, 0.353888888888889, 0.364305555555556,
0.374722222222222, 0.385138888888889, 0.395555555555556, 0.405972222222222,
0.416400462962963, 0.42681712962963, 0.437233796296296, 0.447650462962963,
0.45806712962963, 0.468483796296296, 0.478935185185185, 0.489363425925926,
0.499780092592593, 0.510208333333333, 0.520625, 0.531041666666667,
0.541458333333333, 0.551875, 0.562303240740741, 0.572719907407407,
0.583136574074074, 0.593553240740741, 0.603969907407407, 0.614386574074074,
0.624803240740741, 0.635219907407407, 0.645636574074074, 0.656064814814815,
0.666481481481481, 0.676898148148148, 0.687314814814815, 0.697731481481481,
0.708148148148148, 0.718564814814815, 0.728981481481481, 0.739409722222222,
0.749826388888889, 0.760243055555556, 0.770659722222222, 0.781076388888889,
0.791493055555556, 0.801909722222222, 0.812337962962963, 0.82275462962963,
0.833171296296296, 0.843587962962963, 0.85400462962963, 0.864421296296296,
0.874837962962963, 0.88525462962963, 0.895671296296296, 0.906099537037037,
0.916516203703704, 0.926909722222222, 0.937337962962963, 0.947777777777778,
0.958206018518518, 0.968530092592593, 0.978958333333333, 0.989375,
0.999791666666667, 0.0100694444444444, 0.0204976851851852, 0.0309143518518519,
0.0413310185185185, 0.0517476851851852, 0.0621759259259259, 0.0725925925925926,
0.0830092592592593, 0.0934375, 0.103854166666667, 0.114270833333333,
0.124699074074074, 0.135115740740741, 0.145532407407407, 0.155960648148148,
0.166377314814815, 0.176805555555556, 0.187222222222222, 0.197650462962963,
0.20806712962963, 0.21849537037037, 0.228912037037037, 0.239340277777778,
0.249768518518519, 0.260185185185185, 0.270601851851852, 0.281030092592593,
0.291446759259259, 0.301863425925926, 0.312280092592593, 0.322696759259259,
0.333125, 0.343541666666667, 0.353958333333333, 0.364375, 0.374791666666667,
0.385219907407407, 0.395636574074074, 0.406053240740741, 0.416469907407407,
0.426886574074074, 0.437314814814815, 0.447731481481482, 0.458148148148148,
0.468564814814815, 0.478981481481482, 0.489409722222222, 0.499826388888889,
0.510243055555556, 0.520659722222222, 0.531076388888889, 0.54150462962963,
0.551921296296296, 0.562337962962963, 0.57275462962963, 0.583171296296296,
0.593599537037037, 0.604016203703704, 0.61443287037037, 0.624849537037037,
0.635266203703704, 0.64568287037037, 0.656111111111111, 0.666527777777778,
0.676944444444444, 0.687361111111111, 0.697777777777778, 0.708194444444444,
0.718611111111111, 0.729039351851852, 0.739456018518518, 0.749872685185185,
0.760289351851852, 0.770706018518518, 0.781134259259259, 0.791550925925926,
0.801967592592593, 0.812384259259259, 0.822800925925926, 0.833229166666667,
0.843645833333333, 0.8540625, 0.864479166666667, 0.874895833333333,
0.885324074074074, 0.895740740740741, 0.906157407407407, 0.916574074074074,
0.927002314814815, 0.937418981481482, 0.947835648148148, 0.958252314814815,
0.968668981481482, 0.979097222222222, 0.989513888888889, 0.999930555555556,
0.0100810185185185, 0.0204976851851852, 0.0309143518518519, 0.0413310185185185,
0.0517476851851852, 0.0621759259259259, 0.0725925925925926, 0.0830092592592593,
0.0934259259259259, 0.103854166666667, 0.114270833333333, 0.1246875,
0.135104166666667, 0.145532407407407, 0.155949074074074, 0.166365740740741,
0.176793981481481, 0.187210648148148, 0.197627314814815, 0.208055555555556,
0.218472222222222, 0.228888888888889, 0.239305555555556, 0.249733796296296,
0.260150462962963, 0.27056712962963, 0.280983796296296, 0.291412037037037,
0.301828703703704, 0.31224537037037, 0.322662037037037, 0.333078703703704,
0.343506944444444, 0.353923611111111, 0.364340277777778, 0.374756944444444,
0.385173611111111, 0.395601851851852, 0.406018518518519, 0.416435185185185,
0.426851851851852, 0.437268518518519, 0.447696759259259, 0.458113425925926,
0.468530092592593, 0.478946759259259, 0.489363425925926, 0.499780092592593,
0.510208333333333, 0.520625, 0.531041666666667, 0.541458333333333,
0.551875, 0.562303240740741, 0.572719907407407, 0.583136574074074,
0.593553240740741, 0.603969907407407, 0.614398148148148, 0.624814814814815,
0.635231481481481, 0.645648148148148, 0.656064814814815, 0.666481481481481,
0.676909722222222, 0.687326388888889, 0.697743055555556, 0.708159722222222,
0.718576388888889, 0.728993055555556, 0.739421296296296, 0.749837962962963,
0.76025462962963, 0.770671296296296, 0.781087962962963, 0.791516203703704,
0.80193287037037, 0.812349537037037, 0.822766203703704, 0.83318287037037,
0.843611111111111, 0.854027777777778, 0.864444444444444, 0.874861111111111,
0.885277777777778, 0.895694444444444, 0.906122685185185, 0.916539351851852,
0.926956018518518, 0.937372685185185, 0.947800925925926, 0.958217592592593,
0.968634259259259, 0.979050925925926, 0.989467592592593, 0.999895833333333,
0.0100810185185185, 0.0204976851851852, 0.0309143518518519, 0.0413310185185185,
0.0517476851851852, 0.0621643518518519, 0.0725810185185185, 0.0830092592592593,
0.0934259259259259, 0.103842592592593, 0.114270833333333, 0.1246875,
0.135104166666667, 0.145520833333333, 0.155949074074074, 0.166365740740741,
0.176782407407407, 0.187210648148148, 0.197627314814815, 0.208043981481481
), format = "h:m:s", class = "times"), CPU = c(27.7058823529412,
28.1, 25.5444444444444, 24.4333333333333, 25.3222222222222, 22.3666666666667,
20.8555555555556, 19.5777777777778, 20.8555555555556, 20.0333333333333,
19.1888888888889, 18.5444444444444, 19.3333333333333, 19.0222222222222,
17.3111111111111, 17.2777777777778, 17.2777777777778, 17.1555555555556,
17.2333333333333, 17.3777777777778, 17.5444444444444, 18.2222222222222,
17.7444444444444, 18.6333333333333, 21.6333333333333, 23.9, 27.9666666666667,
28.5222222222222, 32.1777777777778, 33.0111111111111, 36.5222222222222,
38.1111111111111, 43.8, 48.1666666666667, 52.4222222222222, 54.4444444444444,
60.8222222222222, 64.7111111111111, 60.5777777777778, 65.9111111111111,
67.3777777777778, 65.7777777777778, 66.6555555555556, 67.9888888888889,
70.9777777777778, 70.6888888888889, 66.3777777777778, 68.3, 66.0222222222222,
66.1777777777778, 64.9333333333333, 63.8, 66.1444444444444, 65.2888888888889,
63.1222222222222, 61.1666666666667, 62.9, 62.6444444444444, 60.9888888888889,
60.2222222222222, 57.8555555555556, 56.9333333333333, 56.1555555555556,
57, 53.0222222222222, 54.2222222222222, 54.0333333333333, 52.5777777777778,
52.0333333333333, 51.6111111111111, 49.0444444444444, 48.3777777777778,
48.3444444444444, 50.1666666666667, 47.2, 44.4888888888889, 44.5111111111111,
43.7222222222222, 40.6111111111111, 39.2888888888889, 39.5333333333333,
36.6555555555556, 34.1888888888889, 33.6111111111111, 33.9222222222222,
33.3, 31.0777777777778, 29.8333333333333, 29.3444444444444, 29.7888888888889,
27.3888888888889, 25.9444444444444, 24.0666666666667, 23.4, 26.6666666666667,
26.5888888888889, 30.5294117647059, 25.7333333333333, 27.2666666666667,
26.7, 24.8666666666667, 23.3666666666667, 23.6333333333333, 21.7,
19.6666666666667, 22.4666666666667, 19.2333333333333, 20.9, 18.4333333333333,
19.6666666666667, 19.2666666666667, 19.8666666666667, 18.8666666666667,
18.3666666666667, 16.1666666666667, 15.6333333333333, 15.9333333333333,
17.1333333333333, 18.3, 23.7333333333333, 22.4, 20.4333333333333,
18.9666666666667, 19.3333333333333, 22.8333333333333, 25.0333333333333,
26.5333333333333, 29.7333333333333, 34.1666666666667, 35.9333333333333,
39.1, 37.4, 43.9, 38.6333333333333, 46.0333333333333, 49.2, 49.0666666666667,
54.1666666666667, 54.6333333333333, 52, 57.6666666666667, 54.5333333333333,
53.2, 53.8, 54.0666666666667, 61.0666666666667, 56.7333333333333,
53.6, 52.7, 54.9, 51.0333333333333, 53.9333333333333, 52, 49.3,
48.3666666666667, 48.1333333333333, 46.0333333333333, 46.8333333333333,
42.9333333333333, 47.0666666666667, 49.1, 48.6666666666667, 48.4,
42.7333333333333, 45.2333333333333, 37, 37.7666666666667, 36.1333333333333,
40.3666666666667, 39.8666666666667, 36.6333333333333, 38.7666666666667,
40, 34.4666666666667, 34.0333333333333, 35.5, 35.8666666666667,
30.3666666666667, 38.5666666666667, 27.4, 29.3666666666667, 39.6,
45.4333333333333, 61.4666666666667, 62.6666666666667, 61.7, 63.7666666666667,
61.6, 49.8, 52.2666666666667, 44.2666666666667, 37.9, 27.6428571428571,
26.6, 24.4333333333333, 25.1444444444444, 26.5555555555556, 22.0666666666667,
19.8, 19.9555555555556, 20.1111111111111, 18.2444444444444, 18.4333333333333,
17.1777777777778, 17.4333333333333, 18.5777777777778, 17.6888888888889,
16.1111111111111, 17.6777777777778, 17.4333333333333, 16.0888888888889,
17.0444444444444, 16.0444444444444, 15.1777777777778, 14.1888888888889,
16.0888888888889, 17.4222222222222, 17.0222222222222, 18.2111111111111,
20.6, 21.2111111111111, 21.9, 23.1888888888889, 24.9888888888889,
27.7, 30.9333333333333, 32.9444444444444, 35.4333333333333, 36.6666666666667,
40.2333333333333, 39.2222222222222, 40.3777777777778, 45.2444444444444,
46.7666666666667, 48.3777777777778, 51.5888888888889, 53.5222222222222,
42.3157894736842, 34.7866666666667, 32.7733333333333, 36.4466666666667,
31.98, 36.8133333333333, 34.34, 34.8, 34.0266666666667, 33.7733333333333,
32.1266666666667, 33.3066666666667, 34.4733333333333, 31.82,
31.8, 33.84, 33.78, 31.9066666666667, 29.7666666666667, 28.3466666666667,
28.62, 27.9866666666667, 28.82, 27.5, 29.4466666666667, 27.92,
28.0733333333333, 27.2666666666667, 28.0533333333333, 27.52,
25.8866666666667, 26.38, 26.8933333333333, 26.36, 25.88, 25.96,
26.8133333333333, 23.9133333333333, 26.4066666666667, 25.08,
23.7933333333333, 21.2333333333333, 17.3666666666667, 16.4807692307692,
16.9777777777778, 14.9555555555556, 16.3218390804598, 28.8684210526316,
31.6, 38.1, 35.3, 21.8627450980392, 19.3, 17, 16.7, 16.1444444444444,
14.3, 13.7333333333333, 13.4777777777778, 13.0333333333333, 12.1666666666667,
11.3, 11.9111111111111, 11.3222222222222, 11.4555555555556, 10.5333333333333,
10.7777777777778, 10.9111111111111, 11.1, 9.28888888888889, 9.35555555555556,
9.95555555555556, 10, 9.47777777777778, 10.3333333333333, 11.3222222222222,
12.3333333333333, 14.1555555555556, 15.3555555555556, 17.1777777777778,
19.0888888888889, 20.1555555555556, 21.5444444444444, 26.0555555555556,
29.2777777777778, 31.1666666666667, 32.5333333333333, 36.5555555555556,
39.3555555555556, 41.6888888888889, 45.4888888888889, 46.7333333333333,
49.5111111111111, 50.6777777777778, 49.8555555555556, 50.2777777777778,
51.4666666666667, 47.0333333333333, 48.6, 51.1888888888889, 48.6555555555556,
46.5, 44.8444444444444, 45.9, 48.2333333333333, 46.7555555555556,
45.3111111111111, 46.0888888888889, 48.5555555555556, 46.0555555555556,
44.8777777777778, 44.5, 46.0666666666667, 45.6777777777778, 43.6,
44.5888888888889, 46.0555555555556, 45.4111111111111, 44.7555555555556,
43.3222222222222, 43.9888888888889, 43.1666666666667, 42.4777777777778,
41.4, 40.7555555555556, 40.2111111111111, 39.7333333333333, 38.9555555555556,
38.7111111111111, 38.9444444444444, 37.8222222222222, 37.5444444444444,
38.1888888888889, 37.2444444444444, 36.7222222222222, 36.7333333333333,
37.2333333333333, 35.3666666666667, 35.0444444444444, 34.7111111111111,
33.5666666666667, 32.4111111111111, 30.6222222222222, 29.9444444444444,
29.7888888888889, 29.7111111111111, 28.5, 27.6470588235294, 25.9,
24.0222222222222, 22.0444444444444, 22.5888888888889, 19.9888888888889,
17.3555555555556, 17.7555555555556, 17.6, 16.8, 16.2333333333333,
16.1666666666667, 18.5555555555556, 19.0444444444444, 17.6111111111111,
18, 18.3111111111111, 18.5333333333333, 18.2333333333333, 18.1888888888889,
18.2555555555556, 19.1, 18.8777777777778, 19.1333333333333, 20.2777777777778,
21.4111111111111, 23.4444444444444, 25.2777777777778, 27.3555555555556,
29.2666666666667, 31.5555555555556, 32.0888888888889, 34.4333333333333,
36.7444444444444, 38.5777777777778, 41.2555555555556, 42.9777777777778,
44.7777777777778, 44.7444444444444, 44.9333333333333, 48.4666666666667,
46.9888888888889, 47.3333333333333, 48.2777777777778, 47.1333333333333,
48.3444444444444, 48.5555555555556, 51.4222222222222, 49.3444444444444,
47.8222222222222, 45.5888888888889, 46.2888888888889, 47.5666666666667,
45.0111111111111, 45.9111111111111, 46.6333333333333, 43.9777777777778,
46.1777777777778, 44.9, 44.7777777777778, 45.7777777777778, 45.8444444444444,
44.4666666666667, 44.1444444444444, 44.5111111111111, 44.5666666666667,
42.7777777777778, 43.2666666666667, 43.0666666666667, 43.1222222222222,
42.5, 40.6222222222222, 40.2555555555556, 40.7222222222222, 39.8888888888889,
39.6333333333333, 39.1888888888889, 39.6777777777778, 39.1666666666667,
39.5111111111111, 38.2666666666667, 39.0222222222222, 37.5666666666667,
36.6888888888889, 37.4222222222222, 37.5777777777778, 36.8444444444444,
35.7222222222222, 35.7444444444444, 35.9111111111111, 33.2111111111111,
31.8555555555556, 29.5, 28.5888888888889, 27.6333333333333, 29.5555555555556,
29.1960784313725, 28.5555555555556, 26.8333333333333, 25.3222222222222,
25.1555555555556, 23.0555555555556, 22.1777777777778, 20.7333333333333,
20.8222222222222, 20.8, 19.9444444444444, 19.5666666666667, 19,
19.1888888888889, 18.5111111111111, 17.8777777777778, 17.6111111111111,
18.3555555555556, 18.5777777777778, 19.0777777777778)), .Names = c("DATE",
"TIME1", "CPU"), row.names = c(NA, 500L), class = "data.frame")

this part is Brian Diggs code to scale the y-axis:
library(scales)
timesreverse_trans <- function() {
    trans <- function(x) {-as.numeric(x)}
    inv <- function(x) {times(-x)}
    fmt <- function(x) {
        notone <- x != 1
        simplify <- !any(diff(x) < 1/(24*60))
        ifelse(notone,
               format(x-floor(x), simplify=simplify),
               ifelse(simplify, "24:00", "24:00:00"))
    }
    trans_new("chrontimes-reverse",
              transform = trans,
              inverse = inv,
              breaks = pretty_breaks(),
              format = fmt,
              domain=c(0,1))
}
scale_y_times <- function(..., trans=NULL) {
    scale_y_continuous(trans=timesreverse_trans(), ...)
}

I have this data frame tt. When I try to run this code, I dont see the color on the chart. Only very little dots.
library(ggplot2)
library(scales)
library(zoo)
library(xts)
library(chron)

val=c(0,0.29,0.39,0.49,0.59, 0.69,0.79, 0.89, 1)
cols=c("white","#F0FFFF","#AEEEEE","#ADD8E6","#33FFFF","green","yellow","orange", "#FF0000", "#FF0000")
brk = c(20, 30, 40, 50, 60, 70, 80, 90, 100)
    ggplot(tt, aes(DATE, TIME1, fill=CPU)) + geom_tile() + theme_bw() + scale_fill_gradientn(name="CPU Utilization", colours=cols, values=val, limits=c(0,100), breaks = brk) + guides(fill = guide_legend(keywidth = 5, keyheight = 1)) + scale_y_times()

When I subset the tt data frame to one it works.
library(ggplot2)
library(scales)
library(zoo)
library(xts)
library(chron)

 val=c(0,0.29,0.39,0.49,0.59, 0.69,0.79, 0.89, 1)
cols=c("white","#F0FFFF","#AEEEEE","#ADD8E6","#33FFFF","green","yellow","orange", "#FF0000", "#FF0000")
brk = c(20, 30, 40, 50, 60, 70, 80, 90, 100)

ggplot(subset(tt, DATE %in% as.Date(c("2013-02-08"))),aes(DATE, TIME1, fill=CPU)) + geom_tile() + theme_bw() + scale_fill_gradientn(name="CPU Utilization", colours=cols, values=val, limits=c(0,100), breaks = brk) + guides(fill = guide_legend(keywidth = 5, keyheight = 1)) + scale_y_times()

Can somebody tell me how to address this problem?

A: I'm not familiar with the chron package, so maybe this is not the best answer. Your problem originates from the values stored in tt$Time1. They are simply all to unequal to each other which means that for every single value a new tile is created in your plot. In the result your tiles become simply too thin. As far as I see, the best way to overcome this is by rounding the time points using trunc:
tt$TIME1 <- trunc(tt$TIME1, "0:15:00")

Calling then your original code gives

By the way, for so large data, I'd also suggest to use geom_raster() instead of geom_tile() since it's faster.


text:
Q: Computing Autocorrelation with FFT Using JTransforms Library I'm trying to calculate autocorrelation of sample windows in a time series using the code below. I'm applying FFT to that window, then computing magnitudes of real and imaginary parts and setting imaginary part to zero, lastly taking inverse transform of it to obtain autocorrelation:
DoubleFFT_1D fft = new DoubleFFT_1D(magCnt);
fft.realForward(magFFT);

magFFT[0] = (magFFT[0] * magFFT[0]);
for (int i = 1; i < (magCnt - (magCnt%2)) / 2; i++) {
    magFFT[2*i] = magFFT[2*i] * magFFT[2*i] + magFFT[2*i + 1] * magFFT[2*i + 1];
    magFFT[2*i + 1] = 0.0;
}

if (magCnt % 2 == 0) {
    magFFT[1] = (magFFT[1] * magFFT[1]);
} else {
    magFFT[magCnt/2] = (magFFT[magCnt-1] * magFFT[magCnt-1] + magFFT[1] * magFFT[1]);
}

autocorr = new double[magCnt];
System.arraycopy(magFFT, 0, autocorr, 0, magCnt);
DoubleFFT_1D ifft = new DoubleFFT_1D(magCnt);
ifft.realInverse(autocorr, false);

for (int i = 1; i < autocorr.length; i++)
    autocorr[i] /= autocorr[0];
autocorr[0] = 1.0;

The first question is: It is seen that this code maps autocorrelation result to [0,1] range, although correlation is supposed to be between -1 and 1. Of course it is easy to map the results to [-1,1] range, but I'm not sure if this mapping is correct. How can we interpret the values in the resulting autocorr array?
Secondly, with this code I'm geting good results for some periodic series, that is I get higher values for specific autocorrelation indices in accordance with the period of signal. However the result go weird when I apply it to non-periodic signals: all the values in autocorr array appear to be very close to 1. What is the reason for that?

A: For FFT-based algorithms to work, you must pay careful attention to the definitions, including conventions of the library you are using.  You seem to be confusing the "signal processing" convention for AC and the "statistical" one. And then there is FFT wrapping and zero padding.
Here is a code that's working for the even N case, signal processing convention. It's tested against a brute force wrapped autocorrelation.  The comments show how to convert it to the signal processing convention.  For statistical ac, the mean of the data is subtracted out.  This can be done merely by zeroing out the "0Hz" component of the FFT.  Then the zero'th element of the ac is the variance, and you can normalize by dividing through by this quantity.  The resulting values will fall in -1..1 as you say.
Your code seems to be doing the dividing through, but not ignoring the 0 Hz component of the data.  So it's computing some kind of mashup of the conventions.
import edu.emory.mathcs.jtransforms.fft.DoubleFFT_1D;
import java.util.Arrays;

public class TestFFT {

    void print(String msg, double [] x) {
        System.out.println(msg);
        for (double d : x) System.out.println(d);
    }

    /**
     * This is a "wrapped" signal processing-style autocorrelation.
     * For "true" autocorrelation, the data must be zero padded.
     */
    public void bruteForceAutoCorrelation(double [] x, double [] ac) {
        Arrays.fill(ac, 0);
        int n = x.length;
        for (int j = 0; j < n; j++) {
            for (int i = 0; i < n; i++) {
                ac[j] += x[i] * x[(n + i - j) % n];
            }
        }
    }

    private double sqr(double x) {
        return x * x;
    }

    public void fftAutoCorrelation(double [] x, double [] ac) {
        int n = x.length;
        // Assumes n is even.
        DoubleFFT_1D fft = new DoubleFFT_1D(n);
        fft.realForward(x);
        ac[0] = sqr(x[0]);
        // ac[0] = 0;  // For statistical convention, zero out the mean
        ac[1] = sqr(x[1]);
        for (int i = 2; i < n; i += 2) {
            ac[i] = sqr(x[i]) + sqr(x[i+1]);
            ac[i+1] = 0;
        }
        DoubleFFT_1D ifft = new DoubleFFT_1D(n);
        ifft.realInverse(ac, true);
        // For statistical convention, normalize by dividing through with variance
        //for (int i = 1; i < n; i++)
        //    ac[i] /= ac[0];
        //ac[0] = 1;
    }

    void test() {
        double [] data = { 1, -81, 2, -15, 8, 2, -9, 0};
        double [] ac1 = new double [data.length];
        double [] ac2 = new double [data.length];
        bruteForceAutoCorrelation(data, ac1);
        fftAutoCorrelation(data, ac2);
        print("bf", ac1);
        print("fft", ac2);
        double err = 0;
        for (int i = 0; i < ac1.length; i++)
            err += sqr(ac1[i] - ac2[i]);
        System.out.println("err = " + err);
    }

    public static void main(String[] args) {
        new TestFFT().test();
    }
}


text:
Q: iOS4 data protection in MonoTouch? my application downloads files and stores them in the personal folder. I would like to apply iOS4's data encryption but cannot find  equivalants to NSData's write methods which allow protecting files.
Is it in MT? Or are all files protected automatically?
René

A: Looking at the MonoTouch docs, the MonoTouch rosetta stone description of NSData and the Apple docs section on Working with Protected Files the NSData._Save method is what you're looking for in MonoTouch.

A: Use the NSData.Save (string file, NSDataWritingOptions options, out NSError error) API
And make sure that you pass the NSDataWritingOptions.FileProtectionComplete as the options argument.


text:
Q: How to filter Ansible 'find' output I would like to view the list of symbolic links from some remote servers in the terminal, but a lot of information is being printed when I run the playbook.
This is ansible 2.7.12 running on an Ubuntu server. I am using 'find' module and file_type: link to get the softlink details.
Find is returning a lot of details with the return value key "files" but I just need the soft links and corresponding server name in the terminal.
---
# tasks file for application
- name: Get the current applications running
  find:
    paths: /path/to/app
    file_type: link
  register: find_result

- name: Print find output
  debug:
    var: find_result.results

Actual Result:
ok: [client3.example.com] => {
    "find_result.files": [
        {
            "atime": 1559027986.555,
            "ctime": 1559027984.828,
            "dev": 64768,
            "gid": 0,
            "gr_name": "root",
            "inode": 4284972,
            "isblk": false,
            "ischr": false,
            "isdir": false,
            "isfifo": false,
            "isgid": false,
            "islnk": true,
            "isreg": false,
            "issock": false,
            "isuid": false,
            "mode": "0777",
            "mtime": 1559027984.828,
            "nlink": 1,
            "path": "/path/to/app/softlink.1",
            "pw_name": "root",
            "rgrp": true,
            ...
            ...

Would like to get some filtered output in the terminal like:
ok: [client3.example.com] => {
    "find_result.files": [
        {
            "path": "/path/to/app/softlink.1",
},

A: There are a couple of ways of addressing this question.  You could use the map filter to extract just the path attribute from your results:
- name: Print find output
  debug:
    var: results.files|map(attribute='path')|list

Given the sample data in your question, this would result in:
TASK [Print find output] *****************************************************************************************************************************************************
ok: [localhost] => {
    "results.files|map(attribute='path')|list": [
        "/path/to/app/softlink.1"
    ]
}

You can also accomplish something similar using the json_query filter, which applies JMESPath queries to your data:
- name: Print find output
  debug:
    var: results.files|json_query('[*].path')


text:
Q: Which is the correct expression for say that I have two items of three possibilities? Which is the correct expression for say that I have two items of three possibilities?

*

*Two of three?

*Two out of three?

*Other?

A: I think you will want to sort out the full sentence because it would not really work if you are comparing "items" to "possibilities".
Having said that, your two statements are fine depending on how you use them.
You could say "I have two of three possible items" or "I have two out of three possible items" (this seems more concise).
While you could say "I have two of three possibilities", I do not think it makes a great deal of sense.

A: I both "two of three" and "two out of three" are correct ("two of three" might be preferred due to conciseness). For instance, those sound fine to me:

You can pick two out of those three apples.
You can pick two of those three apples.
Students are instructed to pick two out of the three questions in Section B of Paper 1.
Students are instructed to pick two of the three questions in Section B of Paper 1.
Users have two out of three options that are safe in such situation.
Users have two of three options that are safe in such situation.

Though maybe you might want to say "two (out) of three possibilities " or "two (out) of three items".
Some google hits:
"two out of three options" - 302,000 hits
"two of three options" - 2,330,000 hits
"two out of three possibilities" - 130,000 hits
"two of three possibilities" - 261,000 hits


text:
Q: Can't use Control Center when UIAlertView displayed (iOS 7) So i set up a retry connection when reachability detects no connection. I want the user to be able to use the Control Center to re-enable WiFi while the UIAlertView is presented. Anyway I can do this?
Picture Of What Control Center Looks Like
Picture Of A UIAlertView


text:
Q: dissociated variables in array I have a problem with php variables. I use a code that looks like this:
for($i = 0; $i <= $nbRecurrence; $i++) {
    $res = new Reservation();
    $res->setDateDebut($DateDebut->add(new \DateInterval('P1D')));
    $res->setDateFin($DateFin->add(new \DateInterval('P1D')));
    $lesRes[] = $res;
    $this->app['orm.ems']['gestionReservationAuto']->persist($res);
    $this->app['orm.ems']['gestionReservationAuto']->flush();
}

The problem is that although I adds each element in the array, but when I use a var_dump for analysis, all $res in $lesRes are identical. Registered data is yet different in the database ...
How can I do to have an array with $res that do not like?
(if I make a request to have the items I just added in database, I have the same problem, I have an array of x elements $res, which are all identical.)

A: I guess $DateDebut is a DateTime object.
I also guess that Reservation::setDateDebut() looks something like:
class Reservation
{
    private $dateDebut;

    public function setDateDebut(DateTime $dateDebut)
    {
        $this->dateDebut = $dateDebut;
    }
}

And let's write again the code that uses it:
$res = new Reservation();
$res->setDateDebut($DateDebut->add(new \DateInterval('P1D')));

What you miss is the fact that DateTime::add() does not create a new DateTime object but returns a reference to the current object (i.e. return $this;).
This means on each iteration you change the value of object $DateDebut then you pass it to Reservation::setDateDebut() which also doesn't make a copy of it but just links to the object it gets as argument.
After the loop you still have only two instances of DateTime; one of them is accessible through the variable $DateDebut and the members $dateDebut of all the Reservation objects created during the loop. The other instance is $DateFin and the same discussion is valid for it too.
Your code is a victim of variables aliasing.
How to fix it:
You need to create copies of $DateDebut somewhere, either in the loop code (and pass the copies to Reservation::setDateDebut()) or in the body of Reservation::setDateDebut():
// Either
$res->setDateDebut(clone $DateDebut->add(new \DateInterval('P1D')));

// Or
public function setDateDebut(DateTime $dateDebut)
{
    $this->dateDebut = clone $dateDebut;
}

You decide where is the most appropriate place to do it, depending how the rest of the code works with these objects.
Because you change the value of $DateDebut in the loop you should make copies of the object there.
If the class Reservation changes the value of its $dateDebut member then you should (also) clone it in the setter method. This is because the caller of Reservation::setDateDebut() does not expect the Reservation class make changes on the value it passes as an argument.


text:
Q: Error message" The fix-no-tty provisioner could not be found" when I vagrant up with VVV I'm currently trying to create a virtual environment for wordpress development. I've installed Git Bash, ConEmu, Virtual Box, Vagrant, Vagrant Host updater, Vagrant triggers, and Varying Vagrant Vagrants. the first time I used vagrant up, I got this message:
default: Successfully added box 'ubuntu/trusty64' (v20150609.0.10) for 'virtualbox'! There are errors in the configuration of this machine. Please fix the following errors and try again:
vm: * The 'fix-no-tty' provisioner could not be found.
I don't really have any idea what this means and have had little success finding information on the internet. Does anyone know what the fix-no-tty provisioner is and how i could fix it?

A: I encountered the same issue today with a new clone of VVV while running Vagrant 1.6.3. The fix-no-tty provisioner was introduced on April 29. Named provisioner support was added to Vagrant in version 1.7.0. I upgraded to Vagrant 1.7.2 and was able to bring the VM up.


text:
Q: Getting child div columns to inherit height of the tallest column / fill entire parent height Site can be seen here: http://storagestaging.com/pricing/
Question is with regards to the four column pricing grid.
I have a four column pricing grid.  Each column has a different height (due to more or less content).  I'd like to get all four columns to fill the entire length of the tallest column / fill the entire parent div.
I've tried display: table and display:table-cell, and adding height=100% to parent and child divs.  Sometimes I get closer, sometimes I just make it worse.  Any help is very appreciated.
Thanks!

A: In case you do decide to use divs, a JS (this is a jQuery version, if you need vanilla JS lemme know) solution is possible:
var max = 0;
$('.myDiv').each(function() {
    if ($(this).height() > max)
        max = $(this).height();
});
$('.myDiv').css('height', max + ' px');

A: You can do it this css, just the height of the parent div would need to be a fixed value.
See this example here
HTML

CSS
.outer{
  background: #000;
  width: 500px;
  height: 200px;
}

.inner{
  display:inline-block;
  width: 49%;
  height: 100%;

}

.a{
  background-color: green;
}

.b{
  background: red;
}

A: To fulfill my request I just manually set the hight of the parent and child sections.


text:
Q: Wrap_Content in a grid-shaped RelativeLayout I'm working on displaying a simple 9x9 game board using a RelativeLayout.
Each EditText in the board has a custom XML shape in the background, which provides the square's color and border.
The XML is much too large to put here, so here's a link:
pastebin.com/LPDs5MLM
Right now, I'm using hard-coded values for the board and square sizes. This isn't ideal, so I'd like to switch to something scalable. With the board and square sizes hard-coded, my board looks like this:
Link
This is the output I'm looking for. However, when I use "wrap_content" for the board size instead of a hardcoded value, I get this output:
Link
Here's a quick summary of how the RelativeLayout is set up.
The middle square (middle row and column) is defined as:
        <EditText
        android:gravity="center"
        android:selectAllOnFocus="true"
        android:inputType="number"
        android:imeOptions="actionDone"
        android:maxLength="1"
        android:text="M"
        android:id="@+id/textview44"
        android:background="@drawable/square"
        android:layout_height="@dimen/square_size"
        android:layout_width="@dimen/square_size"
        android:layout_centerHorizontal="true"
        android:layout_centerVertical="true"/>

The squares to the left of the middle square are positioned to the left.
Each square is positioned to the left or right of the square before it.
This is repeated for all 9 rows.
        <EditText
        android:gravity="center"
        android:selectAllOnFocus="true"
        android:inputType="number"
        android:imeOptions="actionDone"
        android:maxLength="1"
        android:text="0"
        android:id="@+id/textview43"
        android:background="@drawable/square"
        android:layout_height="@dimen/square_size"
        android:layout_width="@dimen/square_size"
        android:layout_toLeftOf="@id/textview44"
        android:layout_centerVertical="true"
        />

Clearly, something is wrong with the way I made the RelativeLayout. Is there any way to fix this?
Apologies if this is an easy fix, I'm very new to Android development.

A: How about checking GridView instead? Then create a custom adapter and custom layout with EditText for each cell. This way, you only have to set one size in one cell or let the GridView automatically set the sizes equally.


text:
Q: Changing my struct to cpp style struct gives me run time error     typedef struct
{
    int day;
    int month;
    int year;
} Date;

 typedef struct
{
    int a;
    int s;
} MetaData;

struct A
{
    char arrA[10];
    char arrB[10];
    Date    date;
    A(char * arrA, char *arrB, const Date& date)
    {
        strcpy(this->arrA, arrA);
        strcpy(this->arrB, arrB);
        this->date = date;
    }
    A(const A& a)
    {
        strcpy(this->arrA, a.arrA);
        strcpy(this->arrB, a.arrB);
        this->date = a.date;
    }
};
bool operator < (const A & lhs, const A & rhs)
{
    if(strcmp(lhs.arrA, rhs.arrA) == 0)
    {
        if(strcmp(lhs.arrB, lhs.arrB) == 0)
            return false;
        else return strcmp(lhs.arrB, lhs.arrB);
    }
    else
        return strcmp(lhs.arrA, rhs.arrB);
}
 typedef map<A, MetaData> TickerMap;
int main()
{

TickerMap tickerMap;
char x[10], y[10];
Date date;
A a(x, y, date);
MetaData m;
    //tickerMap.insert(make_pair(a, m));
    cout<<"The element is sucessfully inserted"<<endl;
    return 0;
}

Whenever i create a struct with some constructors.It gives me run time error when i insert the object in the map. Can somebody please tell me the exact problem. It will be very helful. When I have normal structs ( C style) there is no problem during insertion.
Error :Run-Time Check Failure #2 - Stack around the variable 'date' was corrupted. (visual Studio)

A: x and y are uninitialized arrays, containing random garbage. In particular, they generally aren't NUL-terminated. When A's constructor strcpys from them, a buffer overrun occurs.
Your program exhibits undefined behavior. To the extent it appears to work with some compilers, it does so purely by accident.


text:
Q: Does a stream close when you return it in a WebOperationContext? I'm returning some images as a stream as part of a WebOperationContext.Current.CreateStreamResponse()
I was wondering if the framework handles the closing of this stream after it gets returned. Or if there was something that you have to do as part of the response in order to close the stream correctly.
Thanks.

A: Well, from what I found, CreateStreamResponse() returns a Message, which implements IDisposable, so it would be best practice to wrap your returned object in a using statement. That should handle closing the stream properly.

A: Implementing using is not a soulution here, i had a situation where the returning content was huge (3 MB) and because i wrapped the WebOperationContext.Current.CreateStreamResponse() inside a using statement, the stream got closed before the content finished, thus the response was blank for the client.
All i did was copy the stream output to a string and use WebOperationContext.Current.CreateTextResponse() inside the using wrap.


text:
Q: onmouseover & onmouseleave functions not working properly I'm new to this site and relatively new to web development. I was trying to incorporate javascript to this webpage I made with just HTML & CSS. This webpage is basically an online store for certain products and what I was trying to do was that when someone has their mouse over one of the products, it would provide some details such as the name of the product and the price and when they move the mouse out, it would go back to just an image of the product. For some reason, with my code, it will change the elements so that it shows the details but it won't change back to the original image after the mouse moves away.
I've tried everything I could think of and the goal of this project was to make sure I had an understanding of javascript so I was trying to do this without any jquery. Any advice would be greatly appreciated.
Here is the code:
        //Holds all div elements with class attribute "productlink" which hold the product images
        var products = document.getElementsByClassName("productlink");

        //When this function is called, the product image is changed to show an image of the product, the name and price
        //classNum - specifc class element being called
        //priceAmount - price of product
        //describe - Description/Name of the product
        function hoverDetails(classNum, priceAmount, describe) {
            //Div container for details, image of product, price of product and description
            var divContainer = document.createElement("div");
            var image = document.createElement("img");
            var price = document.createElement("p");
            var description = document.createElement("p");

            var priceTextNode = document.createTextNode(priceAmount);
            var descriptionTextNode = document.createTextNode(describe);

            description.appendChild(descriptionTextNode);
            price.appendChild(priceTextNode);
            image.src = picArray[classNum];

            divContainer.setAttribute("class", "newdiv");
            image.setAttribute("class", "newimg");
            price.setAttribute("class", "itemprice")
            description.setAttribute("class", "itemdescription");

            products[classNum].parentNode.style.textDecoration = "none";

            divContainer.appendChild(image);
            divContainer.appendChild(description);
            divContainer.appendChild(price);

            //This should replace the current image with the details specified eariler
            //childNode is set to 1 due to a #text node in the div
            products[classNum].replaceChild(divContainer, products[classNum].childNodes[1]);
        }

        //This function, when called, replaces the detailed product with just an image of the product
        function originalImage(classNum) {
            var image = document.createElement("img");

            image.setAttribute("class", "display_image");
            image.src = picArray[classNum];

            products[classNum].replaceChild(image, products[classNum].childNodes[1]);
        }

Here is the element that is referencing these functions:

Don't the mind the variable names and I'm sorry if my code seems too much. Any help would be appreciated.
EDIT: Just to let people know, both functions work. The onmouseleave event works when the onmouseover event is not attached. Additionally, the code works when the onmouseover event is replaced with onclick. When I replace onmouseover with onmouseenter, the code works once but never again. This is very strange.

A: There is actually another mouse event called onmouseout. Add another attribute called onmouseout="removeHoverDetails()" and then inside of removeHoverDetails() select everything and say .visibility = "hidden"; Or whatever way you want to use to get rid of the elements in the popup. Also check out w3schools tutorial on onmouseover and onmouseout: http://www.w3schools.com/jsref/event_onmouseover.asp

A: Okay I found the solution to my problem. I put the onmouseover event on the image element of the "productlink" div an left the onmouseout event on the div and looks to be working fine.


text:
Q: How to display things such as username when youve extended the Django User Model in admin.py so I expanded on the Django User Model and this is what I currently have:
class StudentProfile(models.Model):
    user = models.OneToOneField(User, null = True, related_name = 'StudentProfile', on_delete = models.CASCADE)
    teacher = models.BooleanField(default = False)
    school = models.CharField(max_length = 50)
    #replies = models.ManyToManyField()

class TeacherProfile(models.Model):
    user = models.OneToOneField(User, null = True, related_name = 'TeacherProfile', on_delete = models.CASCADE)
    teacher = models.BooleanField(default = True)
    school = models.CharField(max_length = 100)
    subject = models.CharField(max_length = 100)
    head_of_subject = models.BooleanField(default = False)
    headmaster = models.BooleanField(default = False)
    #reviews = models.ManyToManyField()

class SchoolProfile(models.Model):
    school_name = models.CharField(max_length = 100, default = '')
    identification_code = models.CharField(max_length = 10, unique = True)
    teachers = models.ManyToManyField(TeacherProfile, blank = True)

I am now setting up the admin.py and I was wondering how i could display things such as the users first, last, and username?
This is what I have tried, however it has not worked.
class StudentProfileAdmin(admin.ModelAdmin):
    list_display = ["user.username", "school"]

    class Meta:
        model = StudentProfile

class TeacherProfileAdmin(admin.ModelAdmin):
    list_display = ["user.username", "school"]

    class Meta:
        model = TeacherProfile

class SchoolProfileAdmin(admin.ModelAdmin):
    list_display = ["school_name", "identification_code"]

    class Meta:
        model = SchoolProfile

admin.site.register(StudentProfile, StudentProfileAdmin)

admin.site.register(TeacherProfile, TeacherProfileAdmin)
admin.site.register(SchoolProfile, SchoolProfileAdmin)

Thanks for any help!

A: You can add a function to the modeladmin to return the related user's username
class StudentProfileAdmin(admin.ModelAdmin):
    list_display = ["username", "school"]

    def username(self, obj):
        return obj.user.username

    class Meta:
        model = StudentProfile

Edit: It also works with functions defined on the model. So you could add the username function to the model if you'd  like to keep your admin.py cleaner.
class StudentProfile(models.Model):
    user = models.OneToOneField(User, null = True, related_name = 'StudentProfile',
                                on_delete = models.CASCADE)
    teacher = models.BooleanField(default = False)
    school = models.CharField(max_length = 50)

    @propery
    def username(self):
        return self.user.username


text:
Q: php explode only pre delimiter and ignore rest Is it possible to explode only the text pre delimiter (before the --), but ignore everything after the delimiter on each new line of the entire string.
For instance:
string one -- string two
string three -- string four
string five -- string six

I only want to explode string one, string three and string five and ignore string two, string four and string six.
Thanks

A: You can try:
echo implode(",", array_map(function ($v) {
    return current(explode("--", $v));
}, explode("\n", $string)));

View Output
string one ,string three ,string five

A: It's going to be a multistep process.

*

*First explode by new line

*Second, loop though the lines and explode by ' -- '

*Third, output the first of the matches.

PHP Example
$Param = <<<LONG
string one -- string two
string three -- string four
string five -- string six
LONG;

$Lines = explode("\n", $Param);

$Output = [];
foreach($Lines as $line) {
    $line = explode(" -- ", $line);
    $Output[] = $line[0];
}

var_dump($Output);

Example Output
array (size=3)
  0 => string 'string one' (length=10)
  1 => string 'string three' (length=12)
  2 => string 'string five' (length=11)


text:
Q: Call to the function failing with : ORA-00904: "TEMP_DATA"."P_LNAME": invalid identifier The following function compiles fine. But when a call is made to the function in an anonymous PL/SQL code, the call fails.
Can anyone please suggest why ? I am trying to insert the un-matched (new) data and update the matching (existing) data.
Function Fn_Insert_Data_Using_Merge (p_Id in Number,
                                     p_fname in varchar2,
                                     p_mname in varchar2,
                                     p_lname in varchar2,
                                     p_birth_date in date) Return Boolean
Is
Begin
  Dbms_Output.put_line ('Inside the function Fn_Insert_Data_Using_Merge ...');
  Merge Into test_employee te
    using (select distinct p_Id, p_fname, p_mname, p_lname, p_birth_date
             from test_employee) temp_data
    on (te.first_name = temp_data.p_fname and
        te.middle_name = temp_data.p_mname and
        te.last_name = temp_data.p_lname)
    when matched then
      update
        set first_name = p_fname,
            middle_name = p_mname,
            last_name = p_lname,
            run_status = 'Updated'
    when not matched then
      insert (id, first_name, middle_name, last_name, birth_date, run_status)
        values
             (p_id, p_fname, p_mname, p_lname, p_birth_date, 'Inserted');

  Dbms_Output.put_line ('Returning successfully from the function Fn_Insert_Data_Using_Merge ...');
  Return True;
Exception
  When Dup_Val_On_Index Then
    Dbms_Output.put_line ('The name already exists...Cannot insert again ..');
    Return False;
  When Others Then
    Dbms_Output.put_line ('Facing some critical error : ' || SQLERRM);
    Return False;
End Fn_Insert_Data_Using_Merge;

A: The error is trying to tell you that there is no column in your TEMP_DATA extract named P_LNAME.  There is a parameter to the function named 'p_lname' but in the extract you've assigned no column aliases so there are no named fields.  In addition (although not a cause of the error), doing a DISTINCT from a table with potentially many rows is a slow way to get the function parameters into the temp table in the USING clause; you'd be better off using a SELECT...FROM DUAL.  Try replacing your MERGE statement with the following and let us know how it goes:
Merge Into test_employee te
using (select p_Id as p_Id,
              p_fname as p_fname,
              p_mname as p_mname,
              p_lname as p_lname,
              p_birth_date as p_birth_date
         from dual) temp_data
on (te.first_name = temp_data.p_fname and
    te.middle_name = temp_data.p_mname and
    te.last_name = temp_data.p_lname)
when matched then
  update
    set first_name = temp_data.p_fname,
        middle_name = temp_data.p_mname,
        last_name = temp_data.p_lname,
        run_status = 'Updated'
when not matched then
  insert (id,                first_name,             middle_name,
          last_name,         birth_date,             run_status)
    values
         (temp_data.p_id,    temp_data.p_fname,      temp_data.p_mname,
          temp_data.p_lname, temp_data.p_birth_date, 'Inserted');

Share and enjoy.


text:
Q: Server with 2 NICs The server has a motherboard with built-in NIC that has 2 Ethernet ports. 1st labeled Management, 2nd isn't labeled anything. 2nd NIC is a PCI card plugged into the motherboard, which has 1 Ethernet port.
What is the difference between Ethernet port labelled Management and the rest? When should I use more than one NICs with many Ethernet ports?
I want to use this server for random stuff like a web server and a small game server running in ESXi.

A: Many server and workstation class boards come with remote management options. Depending on the board (and sometimes on a license) you can use these to remote control the server.
Example:
a Dell server with a regular DRAC (Dell Remote Access) has a mini computer build into it which can communicate with a dedicated management Ethernet port. That mini computer can simulate mouse and keyboard events and it can capture the screen output. In other words: you can connect to the management card and do all mostly the same things as if you were physically behind the computer. E.g. power it up and down (without needing an OS, or in case of a crashed OS). You can use the local keyboard and local mouse as if they were connected to the server. You can see what is on the screen... Very handy for remote management.
Similar abilities are available in other brands, often marked ilo (integrated lights out)
Such a device needs to communicate and for that it usually uses an ethernet port. Either a dedicated one (which will be marked 'management' and which will not be useable for the normal OS or it shares one with the normal OS. The latter is more fragile.


text:
Q: Detect if JavaFX application is running in jar vs bundled native application As described in https://docs.oracle.com/javafx/2/deployment/self-contained-packaging.htm#A1324980, you can build self-contained application bundles that appear "native" on the various OS.
Is there a way to determine if the code is run in a self-contained bundle vs code that is run via invoking a jar directly?
JRubyFX applications have a handy "in_jar?" function that is pretty hacky, but pretty convenient.


text:
Q: "Pyrcc5' ImportError: DLL load failed: The specified module could not be found I'm creating a plugin on QGIS for which I'm trying to compile the resources so I can start using it.
I'm following this video: https://www.youtube.com/watch?v=GccxvQ1ypbc roughly around the 3:45 mark.
Plugin is created then I get another message tied to pyrcc5 just like in the video.

I open OSGeo4W Shell in admin mode, I go straight to my plugin's directory and I get this error upon following the same steps the person in the video is doing:

Le module spécifié est introuvable  means The specified module could not be found
Please help, I have no clue what could be the issue. This is what my plugin directory upon creating looks like:

A: First of all, in:
Control Panel\Appearance and Personalization
click in View Tab for uncheck "Hide extensions for known file types" option. Afterward, create a Windows Batch file (.bat extension) with the following content:
@echo off
call "C:\Program Files\QGIS 3.16\bin\o4w_env.bat"
call "C:\Program Files\QGIS 3.16\bin\qt5_env.bat"
call "C:\Program Files\QGIS 3.16\bin\py3_env.bat"

@echo on
pyrcc5 -o resources.py resources.qrc

and save it inside your plugin as compile.bat. In my example plugin (fortextthings), it was saved in following path:
C:\Users\zeito\AppData\Roaming\QGIS\QGIS3\profiles\default\python\plugins\fortextthings

Open a Command prompt and type your equivalent following commands (as follows, it has my plugin path):
cd C:\Users\zeito\AppData\Roaming\QGIS\QGIS3\profiles\default\python\plugins\fortextthings [Enter]
compile.bat [Enter]

As result, it was printed following text without any error message:
C:\Users\zeito\AppData\Roaming\QGIS\QGIS3\profiles\default\python\plugins\fortextthings>pyrcc5 -o resources.py resources.qrc

and, afterward, my plugin was activated in "Manage and Install plugins" menu without any problem.


text:
Q: $A$-algebra B and $Hom_{A}(B,A)$ and their rank. Let $A$ and $B$ be a commutative ring and $B$ an $A$-module, and suppose that $B$ is finitely generated and free as an $A$-module. Is $Hom_{A}(B,A)$ free over $A$ with the same rank as B?
Thanks in advance!

A: Yes.
Hint: What if you considered the map $\text{Hom}_A(A^n,A)\cong A^n$ by the map $f\mapsto (f(e_1),\ldots,f(e_n))$ where $\{e_1,\ldots,e_n\}$ is a basis for $A^n$.
Also useful is the fact that the same statement is true if all instances of "free" are replaced with "projective". Then you merely note that if $P\oplus C=A^n$ then by the above, and the fact that $\text{Hom}_A$ is additive, you get that $\text{Hom}_A(P,A)\oplus\text{Hom}_A(C,A)\cong A^n$. Thus, $\text{Hom}_A(P,A)$ is also f.g. projective.


text:
Q: How can I set the TimeDelay to next day @ 5am in Swift? I am trying to run code in func applicationDidEnterBackground and want to set the timeDelay to be next day @ 5 am.
IE: if the user exits the app on Jan. 1st at 10 pm, I want the timeDelay to be Jan 2nd at 5 am.
Code below:
func applicationDidEnterBackground(_ application: UIApplication) {
        submitBackgroundTasks()
      }

      func submitBackgroundTasks() {
        // Declared at the "Permitted background task scheduler identifiers" in info.plist
        let backgroundAppRefreshTaskSchedulerIdentifier = "bundle ID here"
        let timeDelay = 10.0

        do {
          let backgroundAppRefreshTaskRequest = BGAppRefreshTaskRequest(identifier: backgroundAppRefreshTaskSchedulerIdentifier)
            backgroundAppRefreshTaskRequest.earliestBeginDate = Date(timeIntervalSinceNow: timeDelay)
          try BGTaskScheduler.shared.submit(backgroundAppRefreshTaskRequest)
          print("Submitted task request")
        } catch {
          print("Failed to submit BGTask")
        }
      }

Any suggestions? Thanks.

A: The first step is changing the date to the next day:
let changedDate = Calendar.current.date(byAdding: .day, value: 1, to: Date())!
This changed the date from Jan. 1 at 10 pm to Jan. 2 at 10 pm. We have the correct date, but we need to set the time to 5 am:
let changedTimeAndDate = Calendar.current.date(bySettingHour: 5, minute: 0, second: 0, of: changedDate)!


text:
Q: Make the parts of document clickable in the table of contents (TOC) How can I make the part of the document clickable from table of contents in book class? Despite of the fact I was able to make the chapters and sections clickable (as You can see in the picture below), when it comes to say about parts, brought me a trouble...
My MWE:
\documentclass[12pt, a4paper]{book}

%\usepackage[utf8]{inputenc} - not in lualatex!
\usepackage[polish]{babel}
\usepackage{polski}
\usepackage{indentfirst}

\usepackage[margin={2.5cm,2.5cm,2.5cm,2.5cm}]{geometry}

\usepackage[nottoc]{tocbibind}
\usepackage{tocloft}
\usepackage{xpatch}
\makeatletter
\xpatchcmd{\@part}{%
    \addcontentsline{toc}{part}{\thepart\hspace{1em}#1}%%
}{%
    \addtocontents{toc}{\bfseries\protect\centering\Large\thepart.\hspace{1em}#1\par}%
}{}{}
\makeatother
\usepackage[bookmarks=true]{hyperref}
\usepackage{bookmark}
\usepackage{lipsum}

\makeatletter
\def\contentsline#1#2#3#4{%
    \begingroup
    \Hy@safe@activestrue
    \edef\x{\endgroup
        \def\noexpand\Hy@tocdestname{#4}%
    }\x
    \csname l@#1\endcsname{%
        %\hyper@linkstart{link}{\Hy@tocdestname}{#2}\hyper@linkend
        #2%
    }{%
        %\hyper@linkstart{link}{\Hy@tocdestname}{#3}\hyper@linkend
        #3%
    }%
}
\makeatother

\makeatletter
% Update ToC hyperlinks for Chapters
\patchcmd{\l@chapter}% <cmd>
{{\cftchapfont #1}}% <search>
{\hyper@linkstart{link}{\Hy@tocdestname}{}{\cftchapfont #1}}% <replace>
{}{}% <success><failure>
\patchcmd{\cftchapfillnum}{\par}{\hyper@linkend\par}{}{}
% Update ToC hyperlinks for Sections
\patchcmd{\l@section}% <cmd>
{{\cftsecfont #1}}% <search>
{\hyper@linkstart{link}{\Hy@tocdestname}{}{\cftsecfont #1}}% <replace>
{}{}% <success><failure>
\patchcmd{\cftsecfillnum}{\par}{\hyper@linkend\par}{}{}

%-| | - for parts - here doesn't work... perhaps...
%\patchcmd{\l@part}% <cmd>
%{{\cftpartfont #1}}% <search>
%{\hyper@linkstart{link}{\Hy@tocdestname}{}{\cftpartfont #1}}% <replace>
%{}{}% <success><failure>
%\patchcmd{\cftpartfillnum}{\par}{\hyper@linkend\par}{}{}

\makeatother

\renewcommand{\cftchapaftersnum}{.}
\renewcommand{\cftchappresnum}{\bfseries}
\renewcommand\cftsecpagefont{\bfseries\normalsize}
\renewcommand{\cftchapleader}{\normalfont\cftdotfill{\cftchapdotsep}}
\renewcommand\cftchappagefont{\bfseries\normalsize}
\setlength{\cftbeforechapskip}{0.05cm}
\setlength{\cftchapnumwidth}{1cm}
\renewcommand{\cftsecfont}{\normalfont\normalsize}
\renewcommand{\cftchapfont}{\normalfont\large}
\renewcommand{\cftpartfont}{\bfseries\Huge}

\makeatletter\@addtoreset{chapter}{part}\makeatother%
\renewcommand{\thesection}{\thechapter.\arabic{section}.}

\usepackage{etoolbox}
\makeatletter
\patchcmd{\@makechapterhead}% <cmd>
{\@chapapp\space\thechapter\par\nobreak\vskip 20\p@}% <search>
{\Huge\space}% <replace>
{}{}% <success><failure>
\makeatother

\begin{document}
    \tableofcontents
    \part{Część pierwsza}
    \chapter{Rozdział 1}
    \lipsum[1]
    \section{Sekcja 1}
    \lipsum[2]
    \chapter{Rozdział 2}
    \lipsum[2]
    \section{Sekcja 2}
    \lipsum[3]
    \chapter{Rozdział 3}
    \lipsum[3]
    \section{Sekcja 3}
    \lipsum[4]
    \addtocontents{toc}{\vspace{0.5\baselineskip}}
    \part{Część druga}
    \chapter{Rozdział 1}
    \lipsum[1]
    \chapter{Rozdział 2}
    \lipsum[2]
    \chapter{Rozdział 3}
    \lipsum[3]

    \bookmarksetup{startatroot}
\end{document}


text:
Q: after upgrade python version 3.9 my virtualenv Import "django_filters.rest_framework" could not be resolved After upgrading python version 3.8 to 3.9, I have an issue in my virtual environment  Import "django_filters.rest_framework" could not be resolved.
enter code here
from django_filters.rest_framework import DjangoFilterBackend

class Reviewlist(generics.ListAPIView):
    serializer_class = ReviewSerializer
    filter_backends = [DjangoFilterBackend]
    filterset_fields = ['review_user__username', 'active']

    def get_queryset(self):
        pk = self.kwargs['pk']
        return Review.objects.filter(watchlist=pk)


text:
Q: JPA annotation to save id of an object I have the following bean
@Entity
public class A {
   @id
   @generatedvalue
   int id;
   @Column(name="FIELD1")
   private string field1;

   @Autowired
   private MyType field2;

   //getters and setters
}

I also have a DAO class to access this bean. The application has a database with a table A and 2 fields, field1 and field2. The value that is stored in field2 in the database should be an id of field2, I can ask this via

field2.getId();

How should I annotate this in JPA?

A: JPA shouldn't be using dependency injection annotations like @Autowired. Instead, it seems that what you want is a many-to-one foreign-key relationship (or perhaps just a one-to-one, if field2 can only be associated with one A). Annotate it like this:
@ManyToOne
private MyType field2;


text:
Q: Need help creating a method(function) from a class I am new to python and struggling with a homework problem.  I need to create a method to count the number of credits a student has accumulated, and return that number as a float
I am at a loss on how to proceed.  I have listed the two classes I have created, and need
class Course(object):

    def __init__(self, title, year, semester, credits, grade):
        self.title = title
        self.year = year
        self.semester = semester
        self.credits = credits
        self.grade = grade

class StudentRecord(object):

    def __init__(self, firstName, lastName, dob, hsName, hsCity, hsState, degree, address, transcript = [], newcourse = []):
        self.firstName = firstName
        self.lastName = lastName
        self.dob = dob
        self.hsName = hsName
        self.hsCity = hsCity
        self.hsState = hsState
        self.degree = degree
        self.address = address
        self.transcript = transcript
        self.newcourse = newcourse

    def credits():

I know the first two classes work in my Mimir assignment but am struggling on how to proceed with the def credits():
Any help would be greatly appreciated.

A: It looks like transcript will be the list of Courses the student has completed, while newcourse is the list of Courses being completed this semester.   If so, you need to loop over transcript summing course.credits:
def credits(self):
    return sum(course.credits for course in self.transcript)

You should also read this question and its answers, to learn why the default arguments in your __init__ may cause problems.


text:
Q: What is the RDF data model graph structure? Is RDF data model represents data in a directed acyclic graph or not? I am a bit confused about it.

A: The RDF data model is, technically, a set of triples (each triple consisting of a subject, a predicate, and an object), which can be visualized as a directed, labeled graph.
It is directed because edges correspond to RDF triples, where the source vertex corresponds to the triple's subject, the edge to the predicate, and the target vertex to the object.
It is labeled because both vertices and edges have names (IRIs or literal values).
It is not acyclic; it is perfectly valid to have two triples in an RDF dataset like so:
:a :p :b .
:b :p :a .

or indeed this:
:a :p :a .

It can be considered a hypergraph if you take the notion of named graphs (basically a labeling mechanism for subsets of an RDF dataset) into account.
Note that RDF is not actually formally defined in terms of a (mathematical) graph, but has its formal definitions rooted in set theory instead. See the RDF Semantics specification for details.
For more details on the RDF data model, I suggest you read the RDF Primer and/or the Concepts and Abstract Syntax specification.