## How do I correctly use %p and %f in postgresql.conf to make the Write Ahead Log?

I am attempting to modify postgresql.conf (Postgre SQL 10.0 under Ubuntu 18.04 VPS) to setup the Write Ahead Log (WAL).

AIUI, the commands should be:

wal_level = replica             # minimal, replica, or logical archive_mode = on               # enables archiving; off, on, or always                                 # (change requires restart) archive_command = 'cp %p /var/lib/postgresql/10/main/pg_wal/%f'           archive_timeout = 600           # force a logfile segment switch after this                                 # number of seconds; 0 disables 

AIUI, %p references the database file (to be archived) and %f references the filename that will contain the copy of said database file.

In this case: I am saying to copy every 5 minutes the database file to the /pg_wal directory.

However, this is clearly not correct as the error log files shows:

cp: 'pg_wal/000000010000000000000002' and '/var/lib/postgresql/10/main/pg_wal/000000010000000000000002' are the same file 2020-02-16 21:01:05.857 UTC [20707] LOG:  archive command failed with exit code 1 2020-02-16 21:01:05.857 UTC [20707] DETAIL:  The failed archive command was: cp pg_wal/000000010000000000000002 /var/lib/postgresql/10/main/pg_wal/000000010000000000000002 

So I am not sure how %p and/or %f are supposed to be used. If someone could present the syntax, I would be most grateful.

## How do programmers write exploits from CVE with no known metasploit exploit?

Please don’t just tell me to go read “A Bug Hunter’s Diary” book. I’ve noticed that lots of CVE at www.cvedetails.com do not have publicly available exploits. But they have high scores (ex : more that 9 score) With such a high score, I’d thought exploits would be readily available but it’s not the case (not even present in exploitdb).

So how would a hacker basically, from the description at www.cvedetails.com write an exploit code. Do hackers even bother do that ?

## How to write this access control matrix?

This is a simplified dump for the ls – l shell command in the current folder.

-r--r----- alice admin 1 -r--r--r-- bob bob 2 -rw-rw---- charlie charlie 3 -rw-r----- charlie admin 4 ---x--x--x alice alice editor ---x--s--- bob admin editor-super 

Unix users are alice, bob, charlie. root is the system administrator.

The id command for each user returns:

• id alice: uid=1000(alice) gid=1000(alice) groups=1000(alice),1003(admin)

• id bob: uid=1001(bob) gid=1001(bob) groups=1001(bob)

• id charlie: uid=1002(charlie) gid=1002(charlie) groups=1002(charlie), 1003(admin)

There are 2 executable files:

• editor lets you open a file with Read and Write capabilities;

• editor-super does the same as editor.

Draw up an access control matrix with subjects {alice, bob, charlie} and objects {1,2,3,4} that shows, for each combination of subject and object, whether the subject will be able to read (R), and/or write (W) the respective object.

Note: root should not appear in the matrix.

Below is my solution. How should I complete it?

            1       |       2      |      3      |       4     |  Alice   |    r      |       r      |             |      r      |  Bob     |           |       r      |             |             |  Charlie |    r      |       r      |      rw     |       rw    | 

## MATLAB: Write a function A = mymatrix(X, m, n) which creates an m-by-n matrix A, for arbitrary values of m and n and any length of vector X [closed]

X is a vector i already have… its recommended to use length, mod, reshape, repmat this is what ive got but cant come up with anything further:

function A = myMatrix(myvec, m n)

if length(myvec)< m*n

A=reshape([length(myvec)~mod(m*n)  

i know what im trying to do in the last line but not sure how to type it

thanks

## Can I write portable SQL statements?

I am wondering if it is possible to write SQL statements that are 100% interoperable with most or all databases including:

• Postgres
• Microsoft SQL
• Oracle
• SQLite

(Eg, can I just follow a specific SQL standard? Eg, is there something similar to POSIX compliance standards for SQL?)

If so, are there any linting tools available that I can use in a git post-receive hook to reject SQL usage that doesn’t follow such a standard or non-compliant SQL code without having to try to commit the code on all DBs?

## Thomas write rula andview serializability

Yesterday our Professor told in the class that Thomas Write rule ensures view serializability, but while surfing on this topic today on internet I am not able to find any information about that claim. So is it always $$TRUE?$$

Timestamp ordering ensures conflict serializability

Thomas write rule ensures view serializability

## Is it possible to write a message in Thieves’ Cant?

If you are in an alleyway and want to recruit a group of NPC thieves to rob an enemy of yours, could you use chalk to write a message in Thieves’ Cant for anyone who can read it who comes by, or is Thieves’ Cant a spoken language only?

## How to write the invariants for one version of binary search insertion point (or leftmost entry) algorithm?

If we compare the binary search algorithm (leftmost or insertion point) on Wikipedia:

Algorithm 1:

function binary_search_leftmost(A, n, T):     L := 0     R := n     while L < R:         m := floor((L + R) / 2)         if A[m] < T:             L := m + 1         else:             R := m     return L 

with the one on Rosetta Code:

Algorithm 2:

BinarySearch_Left(A[0..N-1], value) {   low = 0   high = N - 1   while (low <= high) {       // invariants: value > A[i] for all i < low                      value <= A[i] for all i > high       mid = (low + high) / 2       if (A[mid] >= value)           high = mid - 1       else           low = mid + 1   }   return low } 

This binary search is the somewhat more complicated type of binary search, which is to find the leftmost index, or it can be the insertion point (so it is not the “exact match” binary search), as follows:

If the numbers in the array are:

11 22 22 33 44 55 66 

then if the target is 3, then the result should be 0 (3 inserted at index 0).

If the target is 59, then the result should be 6 (inserted at where 66 is), and if the target is 77, then the result should be 7 (inserted to the right of the maximum index, which is adding it as the new, final element).

I found it very easy to establish the invariants and correctness for Algorithm 1:

function binary_search_leftmost(A, n, T):     // Invariant:     // [L, R] inclusive is where the answer could be.     //   so note R is not n - 1 like the "exact match" case, but n,     //   because we can go "one step to the right" to insert     //   as index n     L := 0     R := n      // Invariant:     // note that we keep on looping when L < R, meaning the range     // [L, R] is not "closed".  When L == R, then we have reached     // the answer. Note that unlike the exact match case, here we     // always have an answer, so when L == R, then we already have     // an answer. (because [L, R] is where the answer is, and if     // L === R, we already have the answer either L or R and it cannot     // be anything else)     while L < R:         // Invariant:         // It might be better to use m := L + floor((R - L) / 2)         // here, because of the possible overflow bug. Here we consider         // if L and R differ by 1, such as L == 35 and R == 36, then         // m becomes min(L, R), and down below, since there can be         // only two cases: L := m + 1 which is 36, or R = m which is 35,         // that means the range [L, R] always shrinks.  If L and R          // differ by 2 or more, then it is obvious that [L, R] will         // always shrink.  When L and R differ by 0, the loop will not         // continue. So here we established that there will be no         // infinite loop         m := floor((L + R) / 2)         // if target is, say 55, and A[m] is 25 or 54, now we are         // disqualifying 25...A[m], so we set the lower bound L         // to m + 1 (so we disqualify m as well)         if A[m] < T:             L := m + 1         // Here it is T <= A[m]         // if target is, say 55, and A[m] is 55, 56, 100, or 1000         // now our answer could still be m, because m could be the         // leftmost (we don't know yet), so we don't disqualify m         // and so we disqualify m + 1 and all the way to the end         // of array, so we set R = m         else:             R := m     // Finally, when L == R, we could return either L or R     // In fact, it may be good to assert L == R here     return L 

However, for Algorithm 2, I found it quite difficult to establish invariants. It will be kind of like [low, high + 1] could be where the answer falls into. And if I imagine a high2 === high + 1, then maybe everything can fall into place, with

high = N - 1  high2 = high + 1 = N - 1 + 1 = N   (same as Algorithm 1)  while (low <= high) while (low < high + 1)             (same as Algorithm 1, see below) while (low < high2)                (same as Algorithm 1)  high = mid - 1 high2 = high + 1 = mid - 1 + 1 high2 = mid                        (same as Algorithm 1) 

but the line

mid = (low + high) / 2 

becomes

mid = (low + high2 - 1) / 2 

(I think it is assuming integer arithmetics) so then it is shifting the answer to 0.5 to the left sometimes (and therefore 1 less if taking the floor). But if we look at [low, high] === [35, 37] or [35, 36] or [35, 35], they still work out well. Overall, the invariants seem somewhat awkward and unclear. Are there actually some ways to establish good invariants and correctness for Algorithm 2?

## How to write grammar production rules to describe recursive structures?

I’m trying to describe a data structure by production rules. The structure is recursive; say a list of type $$A$$ made of elements of type $$A$$ or $$B$$.

Writing the grammar, I build this:

$$(S \rightarrow AS|ε)$$ $$(A \rightarrow AA|bA|ε)$$

where $$b$$ is a terminal representing element $$B$$ of my list.

The production $$A \rightarrow AA$$ got me a little baffled… is there something right? Thank you.

## how to write a condition for all elements of a list

I have a list

a={no,no,no,no}; 

now I can want to an If so that if all elements of the above list are “yes” it does something for example printing sth, I tried

a[[All]]=yes;  If[a[[All]]==yes, Print["that's OK"]]; 

but I know my command is wrong, any idea?