Insert or update value on table where values can be repeated multiple times

Previously I was using the following table:

CREATE TABLE Users(user BIGINT PRIMARY KEY,                     item_count INT); 

which allowed me to do a simple upsert:

INSERT INTO Users(user, item_count)  VALUES($  1, $  2)  ON CONFLICT(user) DO  UPDATE SET item_cout = user.item_count + 1; 

However I want to switch my table to have more columns so each user have a different item_count per server so I did:

CREATE TABLE Users(id SERIAL PRIMARY KEY,                     server BIGINT NOT NULL,                      user BIGINT NOT NULL,                      item_count INT); 

However I’m not allowed to do an ON CONFLICT anymore in this case because neither server nor user are unique, and they can be repeated throughout the table for example:

id  server  user  item_count 1        1    1           95 2        2    1          345 3        1    2          594 4        3    1            0 

Is there any way to do an upsert with the second table instead of separating the query into two statements? (one for insert if not exists and one for updating)

Doctest error al intentar capturar Exception Value error

Os reporto un error de testing. Intento capturar el error de introducir un valor negativo en una raíz cuadrada.

Mi código:

import math   def listaraicescuadradas(Listanumeros):     """      la funcion devuelve una lista con la raiz cuadrada     de los elementos pasados en otra lista por argumentos.     >>> lista = []     >>> for i in [4, -9, 16]:     ... lista.append(i)     >>> listaraicescuadradas(lista)     Traceback (most recent call last):         ...     ValueError: math domain error       """     return [math.sqrt(n) for n in Listanumeros ]  import doctest  doctest.testmod() 

El error que me dispara es:

ValueError: line 12 of the docstring for __main__.listaraicescuadradas has inconsistent leading whitespace: 'ValueError: math domain error 

Gracias adelantadas.

How to have a value different from 0 in netstat’s Send-Q column for a socket in the LISTEN state?

I am currently trying to solve a Capture The Flag challenge that involves trying to escalate privileges by taking advantage of an exploit in a bash script.

The script first does the following to get all sockets with TCP protocol in the LISTEN state:

output=$  ($  _netstat -ntpl 2> /dev/null | $  _egrep '^t') 

and then it parses the output line by line. One of the things it does for each line is this:

if [[ "$  cur_syn" == "0" ||  "$  max_syn" != "$  cur_syn" ]]     then    continue fi 

$ cur_syn is the value of the Recv-Q column as returned by netstat, and $ max_syn is the value of the Send-Q column.

So, only a socket that is in the LISTEN state and with Recv-Q != 0 and Recv-Q==Send-Q will pass these checks.

netstat‘s man states that:

Recv-Q Established: The count of bytes not copied by the user program connected to this socket. Listening: Since Kernel 2.6.18 this column contains the current syn backlog.


Send-Q Established: The count of bytes not acknowledged by the remote host. Listening: Since Kernel 2.6.18 this column contains the maximum size of the syn backlog.

The thing is, I seem not to be able to create a socket that has a Send-Q different from 0.

If my interpretation is correct, the Send-Q value for a socket that is listening is the max size of the backlog, which is the backlog param in C’s listen(2) function. But even when I create a listening server socket with a backlog of size 3, netstat still reports the Send-Q as being 0! What am I doing wrong?

FYI, I have managed to make the Recv-Q change by having multiple clients connect to a server socket that has received a SIGSTOP. Recv-Q goes up all the way to maximum size of the syn backlog + 1, and then all connections are refused. But alas,Send-Q remains unchanged.

Value iteration in MDP – updating each state once per inner loop?

In value iteration algorithm we update the utility of all possible states (“for each state update its new utility”).

After we’ve updated all states we check to see if the delta is smaller than some value. If not we loop again over all sates.

If we have 2 adjacent sates say A, B – after updating A we can move on to updating since they are adjacent. Is it possible to go back to update A again since its value will be different again (since B just changed) ? or is the order should be to go over all states exactly once per the inner loop and go back to a state already visited only when we implement the inner loop again ?

Sharepoint List’s Custom Field value appears empty in ssrs report when run in sharepoint integrated mode

I have a sharepoint list that contains custom field(its is developed as .wsp solution), its a file upload control and two rendering templates ‘display’ and ‘edit’ templates are defined. ‘Display’ template displays url of file uploaded using the custom field as ASP Hyperlink.

Template is an .ascx control and its code is as follows:

enter image description here

Then I created .rdl report using report builder to display the Hyperlink field’s url attribute value in one of the columns. SSRS report displays the custom field’s Hyperlink’s url attribute value without a problem.

But problem lies in displaying the hyperlink url attribute value when the same SSRS report is uploaded in share point server Under “Site Assets” Folder inside one of the “Site Collection” that already exists there. Hyperlink Url attribute value is not displayed(all custom field controls related values appears blank). I have used CAML Query(using query designer in ssrs report builder tool) to query the list of Client Details from the sharepoint list(it contains fileupload control details including other text fields)

I am not sure if CAML Query is fully working when the SSRS report built using Report Builder is deployed and run inside sharepoint server. The CAML Query generated to run in SSRS report is copied below:

enter image description here

In above Query ‘All_x0020_Citizenship’ is the reference to file ‘upload field control’ in Sharepoint list mentioned at the beginning. Does this problem has to do with CAML Query?Is the CAML query has to be different to run under sharepoint server through sharepoint report service?

May be i need to change custom control code to be rendered which is complaint with sharepoint report service integrated mode? If so please provide some idea on how program custom control code such that its value can be displayed correctly in ssrs report in sharepoint server.

My Sharepoint List’s AddItem.aspx page view looks as follows:

enter image description here

Please look into the issue and shed some lights on how to find a solution or alternatives to display hyperlink field value in ssrs report in sharepoint integrated mode.

Hope you’d let me know if any part of my post is unclear to you so that i can explain further to clarify any confusion on my post. Any help would be greatly appreciated.

Get first non null object, non empty string field value from a list

I have a

List<ClassA> listOfClassA; 

ClassA contains another object let say insideObj. I want to fetch the first instance of insideObj which is non null, and contains a non empty field which is a string. Currently i am doing

for (ClassA objA : listOfClassA) {         if(objA.getInsideObj() != null && !objA.getInsideObj().getName().isEmpty())             return objA.getInsideObj().getName();     } 

Is there a cleaner way to do this in Java 8?

Applying mean value theorem 1 to expectation.

I wanna prove that for an arbitrary real random variable $ X$ defined on some continuous and closed interval $ S$ , if functions $ h(x)$ and $ g(x)$ are bounded, continuous and non-zero over $ S$ , we can find some $ x_0 \in S$ such that $ $ \frac{\mathbb{E}[h(X)]}{\mathbb{E}[g(X)]} = \frac{h(x_0)}{g(x_0)} $ $ $ X$ can be either continuous or discrete.

My proof is $ $ \frac{\mathbb{E}[h(X)]}{\mathbb{E}[g(X)]} = \frac{\int_S h(x) d F_X(x)}{\int_S g(x) d F_X(x)} = \frac{\int_S \frac{h(x)}{g(x)} g(x) d F_X(x)}{\int_S g(x) d F_X(x)} = \frac{\frac{h(x_0)}{g(x_0)} \int_S g(x) d F_X(x)}{\int_S g(x) d F_X(x)} = \frac{h(x_0)}{g(x_0)} $ $ because $ h(x)/g(x)$ is continuous on $ S$ . Is there anything I am missing? Not an expert in probability, so I am wondering if there is any formal theorem for this result.