Integrity constraint violation in my api platform relation

Question: Symfony : 4.4
API PLATFORM : 2.5

I have to entities : Client & Location : a client have many locations, a location is related to one client
Client Entity:
    /**
 * @ORM\Entity(repositoryClass="App\Repository\ClientRepository")
 *
 *
 * @ApiResource(
 *     normalizationContext={"clients:get"},
 *     collectionOperations={
 *          "get"={
 *              "normalization_context": { "groups" = {"clients:get"} },
 *          },
 *          "post"={
 *               "security"="is_granted('IS_AUTHENTICATED_ANONYMOUSLY')",
 *               "normalization_context": { "groups" = {"client:get"} },
 *               "denormalization_context": { "groups" = {"client:create"} },
 *               "method"="POST",
 *               "controller"=ClientCreate::class
 *          }
 *     },
 *     itemOperations={
 *          "get"={
 *              "normalization_context": { "groups" = {"clients:get"} },
 *           },
 *          "put"={
 *               "security"="is_granted('IS_AUTHENTICATED_ANONYMOUSLY')",
 *               "normalization_context": { "groups" = {"client:get"} },
 *               "denormalization_context": { "groups" = {"client:put"} },
 *          },
 *     }
 * )
 *
 */
class Client implements UserInterface
{
    /**
     * @ORM\Id()
     * @ORM\GeneratedValue()
     * @ORM\Column(type="integer")
     *
     * @Groups({"clients:get"})
     *
     */
    private $id;

    /**
     * @ORM\OneToMany(targetEntity="App\Entity\Location", mappedBy="client", cascade={"persist", "remove"}), orphanRemoval=true)
     *
     *@Groups({"client:create","client:get","client:put"})
     *
     * @ApiSubresource()
     *
     */
    private $locations;

Location Entity:
/**
 * @ORM\Entity(repositoryClass="App\Repository\LocationRepository")
 *
 * @ApiResource()
 *
 */
class Location
{
    /**
     * @ORM\Id()
     * @ORM\GeneratedValue()
     * @ORM\Column(type="integer")
     *
     */
    private $id;

    /**
     * @ORM\Column(type="string", length=255, nullable=true)
     *
     * @Groups({"client:create","client:get","client:put"})
     *
     */
    private $address;

//... others attributes

    /**
     * @ORM\Column(type="string", length=255)
     *
     * @Groups({"client:create","client:get","client:put"})
     *
     */
    private $locationName;

    /**
     * @ORM\ManyToOne(targetEntity="App\Entity\Client", inversedBy="locations", fetch="EXTRA_LAZY")
     * @ORM\JoinColumn(nullable=false)
     */
    private $client;

I'm trying to make the relation Client-Location behaves like when I create a client => locations are created => that's works OK for me with this code.
and also I want when I put a client, its old locations are removed, and It creates a new locations that are attached to this client but I got error in put.
Action
PUT /api/clients/58
Body:
{
    "locations": [
        {
            "address": "dfsdfaaaaaaaa",
            "locationName": "sdfsdf"
        }
    ]
}

RESPONSE:
{
"@context": "/api/contexts/Error",
"@type": "hydra:Error",
"hydra:title": "An error occurred",
"hydra:description": "An exception occurred while executing 'UPDATE location SET client_id = ? WHERE id = ?' with params [null, 24]:\n\nSQLSTATE[23000]: Integrity constraint violation: 1048 Column 'client_id' cannot be null",
"trace": [
    {
        "namespace": "",
        "short_class": "",
        "class": "",
        "type": "",
        "function": "",
        "file": "/home/karimengineer/Desktop/SystemFood/api/system_food_api/vendor/doctrine/dbal/lib/Doctrine/DBAL/Driver/AbstractMySQLDriver.php",
        "line": 103,
        "args": []
    },

Comment: weird. the only difference i noticed between your code and mine is the **@ApiSubResource** annotation and **fetch="EXTRA_LAZY"**. Can you try to put without ? Also, what happen when you update an additional field than __locations__?
Comment: @rugolinifr OK I did it, and nothing change, the same error appears, and when I remove "client:put" group from location field, the request passes and the other fields than locations are updated correctly.
Answer: You need to add orphanRemoval=true and cascade={"persist", "remove"} to you locations variable in your Client entity


Mostrar dados de uma função ajax, em outra função ajax

Question: Tenho uma função ajax que procura o código de todas as empresas e vai na outra função ajax procurar os funcionários.
Para que a página não trave ao fazer essa procura estou utilizando o atributo async: true, só que ao fazer isso, não consigo o retorno dos dados na página mesmo funcionando usando o console.log()
Segue meu código para ser analisado

$( document ).ready( function(){
   empresas()

  } )

  let empresasArr = {
 "empresa":[
  {
    "nome": "Digiboard",
    "id": 1
  },
  {
    "nome": "HAM",
    "id": 2
  }
  ]
  }

  let dadosArr = {

   "dados": [
      {"nome": "Carlos", "empresa": 1},
      {"nome": "Vicente", "empresa": 2},
      {"nome": "Maiza", "empresa": 2},
      {"nome": "Charles", "empresa": 1},
      {"nome": "Michel", "empresa": 2}
       ]
  }
  function empresas(){
    $.ajax({
   url: 'https://api.myjson.com/bins/b0c22',
   type: 'post',
   dataType: 'json',
   async: false,
 }).done( function( d ){
    var retorno = "";
    let string = ""
    console.log( d )

    $.each( d.empresa, function(i, j){
        console.log( j.nome )

     retorno = fnNomes( j.id, function( retorno ){
    //console.log( retorno )
    string =+ retorno
     }  )

    })
    console.log( string )
    $('.retorno').append(string)
 })
  }

  function fnNomes( id, cb ){

 let nomes = "";

 $.ajax({
    url: 'https://api.myjson.com/bins/1cksbu',
    type: 'POST',
    async: true,
    dataType: 'json',
    data: { empresa : id }
  }).done( function( d ){

    console.log( d )
    $.each( d.dados, function(i, j ){
     if( j.empresa == id ){

           nomes += j.nome+"
"
     }
    })

    cb( nomes )

  } )
 // console.log(nomes);
  return nomes
  }

o arquivo Empresa.json
{
 "empresa":[
    {
      "nome": "Digiboard",
      "id": 1
    },
    {
      "nome": "HAM",
      "id": 2
    }
 ]
}

O aqruivo dados.json
"dados": [
   {"nome": "Carlos", "empresa": 1},
   {"nome": "Vicente", "empresa": 2},
   {"nome": "Maiza", "empresa": 2},
   {"nome": "Charles", "empresa": 1},
   {"nome": "Michel", "empresa": 2}
  ]

Ouvi falar num tal de deferred e promised, não se resolveria o problema, mas ainda não entendi como usálos
Answer: Da forma que você está fazendo não seria necessário fazer o primeiro Ajax síncrono, até porque isso não é uma boa prática. O Ajax deve ser assíncrono, como o próprio nome sugere: Asynchronous JavaScript e XML.
O erro está na forma em que você está requisitando as páginas usando type: 'post'. O type: 'post' seria no caso de você enviar informações via data:, o que não é o caso. O que você deseja é receber um JSON (dataType: 'json').
Solução:

remova as linhas type: 'post',
remova async: false, e async: true, (o true não é necessário porque o Ajax já é async)

Desta forma o segundo Ajax será chamado normalmente quando o primeiro for concluído (.done()).
Comment: No segundo eu gostaria de enviar o post


Transparention of UIController in Swift - what segue chose?

Question: I am trying to chose right segue to have good "DropDown" in swift UIKit.
Only progress I have made is this:

or this:

My point is that i want the combination of these two. I don't want popover but also i wanna see the top part of the last controller. Is that even possible?
Answer: Unfortunately, Apple doesn't hand you one of these "half covering" presentations on a silver platter; you have to build it yourself. Use a presented view controller whose modal presentation style is custom and provide a transitioning delegate. Now you can make a custom transition animation with a custom UIPresentationController that puts you in charge of where the presented view controller's view will go. Adding the "shadow view" behind the presented view is up to you as well, so if you don't want it, don't add it.
Comment: Thank you, you were right that apple doesn't have it. But CocoaPods have DropDown module that works exactly I need.
Comment: Yeah, he who lives by the third-party code dies by the third-party code, but I do appreciate that sometimes you just need to get work done and move on.


Replacing a character within a string?

Question: What is wrong with the following Python code for replacing "." with "-"
x = 'BRK.B'
if "." in x
    spot = x.find('.')
    x(spot)="-"

Comment: @KeerthanaPrabhakaran doesn't really make a difference as Python strings are immutable. Either way doesn't work. Both result in a `TypeError`
Comment: shouldn't that be x[spot] !! and not x(spot)!!!
Comment: and if you want to replace.. use x.replace(".","-")
Comment: thats true, that is why added the next comment.
Answer: You have some typos, that makes your code unworkable.
Even if you fix this, x is a string, and string is not mutable.
You can just use str.replace.
 x = x.replace('.','-')

Comment: and this is supposed to be a comment!
Comment: @KeerthanaPrabhakaran Really? How did it just "ask for more information or suggest improvements"? To me it looks like it was a (partial) answer, and we're explicitly told to "Avoid answering questions in comments".
Comment: People often write the shortest answer that satisfies the OPs question, and then elaborate consistently. May be you people don't like that.
Comment: not really! And this is anyway a possible duplicate of http://stackoverflow.com/questions/1228299/change-one-character-in-a-string-in-python
Comment: There's nothing wrong with submitting a partial answer that you then add more detail to, but the initial answer _must_ be an adequate answer in its own right.
Answer: You could just use replace:
>>> 'BRK.B'.replace('.', '-')
'BRK-B'

If you only want to replace the first occurence :
>>> 'BRK.B'.replace('.', '-', 1)
'BRK-B'

If for some reason, you really want to do it yourself :
x = 'BRK.B'
if "." in x: # <- Don't forget : after x
    spot = x.find('.')
    # You're not allowed to modify x, but you can create a new string
    x = x[:spot] + '-' + x[spot+1:]
print(x)
# 'BRK-B'

Replacing a character within a string?


How To Crash UTF-8 Encode

Question: I am looking for a string that will crash python3 when encoding it to UTF8.
<code>s=?
s.encode("UTF-8") -> results in error
</code>
Thank you for your help
Comment: Sorry, what's a CTF?
Comment: Why do you think such a string exists?
Comment: I'm not sure it exists, i need it to solve a CTF. There might be another way though..
Comment: An error isn't the same as a crash, you can generally catch an exception to keep the program running.
Comment: @Mark Ransom yes, you are right. In this case I need python to throw an error and to execute code in the catch block.
Comment: https://stackoverflow.com/questions/51972941/python3-an-example-string-that-would-cause-unicodeencodeerror
Answer: The UTF-8 encoder does not allow Unicode strings to use the the UTF-16 "surrogate" code points from U+D800 to U+DFFF:
<code>>>> s = '\ud800'
>>> s.encode('UTF-8')
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
UnicodeEncodeError: 'utf-8' codec can't encode character '\ud800' in position 0: surrogates not allowed
</code>
Comment: wow, thanks a lot. That is exactly what I need!

How To Crash UTF-8 Encode


How to make a function use a variable outside the function, but in a method of a class

Question: I am trying to make a function that will be able to access a variable from outside the function. However, this variable needs to be defined in a class.  I'll define a simplified function of what I am trying to do in code for clarity.
class Stuff():
     def __init__(self):
         print("Initialized")

     def forward(self,x):
         y=4
         x=func(x)
         return x

def func(x):
   global y
   return x+y

stuff = Stuff()
print(stuff.forward(4))

So, I am trying to make func(x) use the y defined in the "forward" method, but when I run this code, I get the error "global name y is not defined". Any help is much appreciated.
Comment: The `global` statement is used to declare a name being 'not local' in a function that alters it. You put it in the wrong place.
Comment: What you *really* should do, however, is pass in `y` as an argument to `func()`. Why do you think you need a global in the first place?
Comment: make `func(x, y)` and call it with your `y` variable
Comment: Put differently: any name *not* being bound to (assignment is one form of binding) is *already a closure or a global*. `y` doesn't get bound to in `func()`, it thus a global name. `y=4` binds `y` in `forward()`, making it local, automatically. `global y` changes the scope there, because it is there that it matters.
Comment: @MartijnPieters Should i delete this question since it seems the answer lies in a different post?
Comment: You can't, because there is an upvoted answer (which has a strange, incorrect first paragraph, at least in this context), that you marked accepted. And you don't need to, either, duplicate posts *can* help future visitors find the canonical post on the subject.
Answer: You can't. A member variable belongs to a specific instance of a class. You have to know the instance to do that, so you'd better pass y to your function as well.
You could do the opposite though. use global in the forward function to define a global y variable, and then access it from the func. However, don't. It's bad practice, always. Pass y to func instead.
Comment: @RohanSingh: Just put `global y` before `y = 4`. the `global` keyword means: when I refer to `y`, use the global one, if it exists, or create it, if it doesn't
Comment: @RohanSingh: ok, creating a global variable is the same, whether in a function or a method
Comment: This has nothing to do with member variables. a) that's not a concept in Python. b) if you are talking about instance attributes, then there is no `self.y` involved here. It's *just another local*. Methods are no different here from regular functions.
Comment: Put differently: **you can do what the OP wants, trivially**, but the OP shouldn't.
Comment: How can I define a global variable in a method? btw, I know what I'm asking sounds silly, but I need it for a larger program I am writing.
Comment: @RohanSingh: Methods are just functions. They are not special when it comes to scoping rules. See the duplicate, and my comments. Put `global y` *in the `forward` function body*.
Comment: Ok thank you for your answers, I guess this question boiled down to creating a global variable in a method.


Does $\lim \frac {a_n} {b_n}$ exist and $\lim a_n \neq 0$ imply $\lim b_n$ exist?

Question: Suppose $\lim_{n \rightarrow \infty} \frac {a_n} {b_n}$ exist and $(a_n)$ converges to some number $k \neq 0$. Is it then possible to conclude that $(b_n)$ converges ?
Also, suppose $\lim_{n \rightarrow \infty} \frac {a_n} {b_n}$ exist and $(b_n)$ converges to some number $k \neq 0$. Is it then possible to conclude that $(a_n)$ converges ?
I am well aware of the statement that if $(a_n)$, $(b_n)$ converges and $b_n\neq 0$ for $n \ge N$ then $\lim_{n \rightarrow \infty} \frac {a_n} {b_n} = \frac {\lim_{n \rightarrow \infty} a_n} {\lim_{n \rightarrow \infty} b_n}$. I've tried to use the contrapositive of this statement to prove my hypotheses. It should be said, that this is not an exercise, but something I've been wondering about.
Comment: $$\frac{a_n}{a_n/b_n} = \,?$$
Comment: Thanks ! I cannot believe I haven't thought of that.
Comment: For the second statement, I must also assume $a_n \neq 0$ for $n \ge N$ ??
Comment: Isn't there an extra case when $\lim_{n\to\infty}{\frac{a_n}{b_n}}=0$? If $a_n\to 0$, we could still have divergence for $b_n$, unless you count $\infty$ as a proper limit. Very pretty way to go about the problem, though.
Comment: No, $a_n$ can be $0$ without problem, there we look at $b_n\cdot \frac{a_n}{b_n}$.
Answer: For the first statement you might try to do:$\lim\frac{a_n}{\frac{a_n}{b_n}}$ but if you consider the case where: $a_n=1+\frac 1n$ and $b_n=n$ then $\lim\frac{a_n}{b_n}=\lim \left( \frac 1n+\frac 1{n^2}\right)=0$ and $\lim a_n=1$ but $\lim b_n=\infty$
And for the second part:$\frac{a_n}{b_n}b_n=a_n$
$\frac{a_n}{b_n}$ is converges and $b_n$ is converges and product of two converges series is converges therefore $a_n$ is converges


About the rank of a solution of a matrix linear differential equation

Question: I have the differential equation $$\partial/\partial t A(t)=B(t)A(t)$$ on the interval $[0,1]$ with initial condittion $A(0)=A_0$. Here $A$ and $B$ are $n\times n$ real matrices depending smoothly on $t$.
I want to prove that the solution $A(t)$ has constant rank on $[0,1]$.
A result by Magnus* states that the solution has the expression $$A(t)=\exp(\Omega(t))A(0)$$
for a suitable $\Omega(t)$. The thing is that this experession holds only on a neighborhood of $0$. Some extra conditions on $B$ would gurantee that in fact such expression holds in $[0,1]$, but in my case $B$ is quite general.
Is there any other result that could help me in this case?
*Magnus, W. (1954), On the exponential solution of differential equations for a linear operator. Comm. Pure Appl. Math., 7: 649–673.
Answer: Use that
$$
\det(A(t))=\exp\left(\int_0^t\text{trace}(B(s))ds)\right)·\det(A(0))
$$
to conclude that if $A(0)$ has full rank then also $A(t)$ has full rank.
Replace linearly dependent columns of $A(0)$ by independent ones until the new matrix $\tilde A(0)$ has full rank. $A(0)$ and $\tilde A(0)$ still coincide in $k=\text{rank}(A(0))$ columns, and as the columns integrate independently, these same columns still coincide in $A(t)$ and $\tilde A(t)$ and are thus linearly independent. It is easy to show that the dependent columns of $A(0)$ stay dependent with exactly the same linear combinations in $A(t)$.


Qual a diferença entre arquivos executáveis gerados usando chmod e os gerados a partir de uma compilação?

Question: Quando uso Python no Linux, costumo transformar arquivos de extensão .py em executáveis usando o chmod. Exemplo:
Arquivo user_sum_python.py:
#!/usr/bin/env python
def user_sum(L):
    if len(L)==1:
        return L[0]
    else:
        return L[0]+user_sum(L[1:])
print(user_sum([2,4,8,23,56,21,20,4,87]))

Na linha de comando:
chmod +x user_sum_python.py

E, assim, posso rodar o programa usando apenas ./user_sum_python.py.
Por outro lado, se escrevo o mesmo programa em uma linguagem que faz compilação, o computador já retorna um executável. Exemplo usando Rust:
Arquivo user_sum_rust.rs:
fn user_sum(lista: &[i32]) -> i32 {
    if lista.len() == 1 {
        return lista[0];
    } else {
        return lista[0] + user_sum(&lista[1..]);
    }
}

fn main() {
    let one_list: [i32; 9] = [2, 4, 8, 23, 56, 21, 20, 4, 87];
    println!("{}", user_sum(&one_list));
}

Rodando rustc user_sum_rust.rs no terminal, o programa gera um arquivo que posso rodar usando ./user_sum_rust.
Qual a diferença entre os dois procedimentos? Existem vantagens e desvantagens associadas a cada um deles?
Comment: Simplesmente o compilador do rust executou o chmod depois da compilação. A pergunta está misturando duas coisas que não tem relação direta (programa executável com flag autorizando executar). o "+x" do linux simplesmente indica que o usuário tem autorização para pedir para o ambiente executar aquilo. Você pode dar um chmod +x num jpeg se quiser. Só que não serve pra muita coisa, pois você autorizou o user a executar algo que não é executável.
Comment: Inclusive, sem o +x você pode continuar executando o .py usando o python diretamente. Aí ja é uma terceira coisa, que é o shell do linux usando o +x com outra finalidade, já descrita aqui https://pt.stackoverflow.com/questions/57702/70
Comment: Eu não disse "só". Ele compilou. Depois, rodou o chmod (pra você não ter que fazer 2 passos). O rust está gerando um executável. Seu .py não é um executável, é só um script (quem roda ele é o Python, mesmo que chame ele diretamente - veja o link que passei anteriormente - não é ele sozinho), então não precisa ser compilado.
Comment: Em tese, sim. Claro que tem outros N fatores. Na verdade nem precisa remover o Py, se tirar ele do caminho indicado na 1a linha do seu script já impede execução direta. Tanto é que quando você roda o rustc ele gera outro arquivo (sem a extensão rs) para você executar (você não roda o source). O py não, você está chamando o arquivo original.
Comment: Acho que dá pra começar por aqui: [O que é uma linguagem de script](https://pt.stackoverflow.com/q/17082/70) e pelos links da resposta aqui: [Linguagem de script sempre é construída sobre outra linguagem?](https://pt.stackoverflow.com/q/216217/70) - em tese, responderia ao problema central da pergunta.
Comment: Vale a pena ler sobre _Shebang_: https://pt.wikipedia.org/wiki/Shebang
Comment: O rust só executou o chmod? Então quer dizer que se eu rodar `chmod +x user_sum_rust.rs` eu terei o mesmo resultado que rodando `rustc user_sum_rust.rs`?
Comment: então se eu remover o rust do meu computador o comando `./user_sum_rust` continuará funcionando, mas se eu remover o python o comando `./user_sum_python.py` vai parar de funcionar?
Answer: Quando você utiliza o chmod com o +x em algum arquivo, você não está necessariamente transformando-o em executável. Na verdade você está dizendo que este arquivo agora terá permissão para ser executado.
No caso do seu arquivo .py, ele é interpretado pelo binário do python por que a primeira linha do arquivo informa que isso deve acontecer: #!/usr/bin/env python. Também conhecido comoShebang.
Do mesmo jeito que, se você trocar por #!/bin/bash, este arquivo será executado pelo bash. Que não conhecerá as instruções do python e dará erro. Ou seja, a extensão .py não é a responsável por quem rodará o arquivo, quem faz isso é a instrução da primeira linha.
Em relação ao seu exemplo com Rust, de fato é diferente para comparar com Python. Uma vez que o Rust realmente pega seu código e o compila, te dando um novo arquivo (este sim podemos chamar de executável, para facilitar) que não mais será processado pelo Rust, pois já está 'convertido' para bytecode (linguagem de máquina).
Quando você escreve códigos de linguagem compiladas, a execução não é do código que você escreveu diretamente, mas sim do resultado da compilação desse código pela linguagem. Diferente do Python e do PHP por exemplo, que são interpretadas pelo próprio binário da linguagem.
Essa história vai bem longe em termos de quando usar o que e posso te afirmar que o aprendizado é super rico e válido.


How to randomly pick k items from a list of n size in python

Question: I want to know how to randomly pick k items from a list of n size for ALL possible combinations.

For example, let A = [1, 2, 3, 4] and K = 3. Then it should return [1, 2, 3], [1, 2, 4], [1, 3, 4], and [2, 3, 4].
Comment: Any attempt from your side.
Comment: What part of this is random?
Answer: You are looking for itertools.combinations. For example:
>>> my_list = A = [1, 2, 3, 4]
>>> k = 3

>>> from itertools import combinations
>>> list(combinations(my_list, k))
[(1, 2, 3), (1, 2, 4), (1, 3, 4), (2, 3, 4)]

Answer: If the ordering inside the results matters you might use itertools.permutations to get all permutations as well - putting them into a set removes duplicates stemming from duplicate numbers in your list
import itertools

n = 3
my_list =  [1, 2, 3, 2 ,1]

print( set(itertools.permutations(my_list, n))) # or list, see below

Output:
{(1, 2, 1), (3, 1, 2), (2, 3, 2), (1, 3, 2), (3, 1, 1), (3, 2, 1), (1, 2, 2),
 (1, 1, 3), (2, 2, 1), (2, 1, 1), (1, 3, 1), (2, 3, 1), (1, 2, 3), (1, 1, 2), ...}
 # with set: 17 items

[(1, 2, 3), (1, 2, 2), (1, 2, 1), (1, 3, 2), (1, 3, 2), (1, 3, 1), (1, 2, 2),
 (1, 2, 3), (1, 2, 1), (1, 1, 2), (1, 1, 3), (1, 1, 2), (2, 1, 3), (2, 1, 2), ...]
 # with list: 60 items

Difference between permutations and combinations:
# permutations - based on all values on any position in the resulttuple
[(1, 2, 3), (1, 2, 2), (1, 2, 1), (1, 3, 2), (1, 3, 2), (1, 3, 1), (1, 2, 2), (1
, 2, 3), (1, 2, 1), (1, 1, 2), (1, 1, 3), (1, 1, 2), (2, 1, 3), (2, 1, 2), (2, 1
, 1), (2, 3, 1), (2, 3, 2), (2, 3, 1), (2, 2, 1), (2, 2, 3), (2, 2, 1), (2, 1, 1
), (2, 1, 3), (2, 1, 2), (3, 1, 2), (3, 1, 2), (3, 1, 1), (3, 2, 1), (3, 2, 2),
(3, 2, 1), (3, 2, 1), (3, 2, 2), (3, 2, 1), (3, 1, 1), (3, 1, 2), (3, 1, 2), (2,
 1, 2), (2, 1, 3), (2, 1, 1), (2, 2, 1), (2, 2, 3), (2, 2, 1), (2, 3, 1), (2, 3,
 2), (2, 3, 1), (2, 1, 1), (2, 1, 2), (2, 1, 3), (1, 1, 2), (1, 1, 3), (1, 1, 2)
, (1, 2, 1), (1, 2, 3), (1, 2, 2), (1, 3, 1), (1, 3, 2), (1, 3, 2), (1, 2, 1), (
1, 2, 2), (1, 2, 3)]

# combinations - based on position in source list not on value order in tuple preserved
[(1, 2, 3), (1, 2, 2), (1, 2, 1), (1, 3, 2), (1, 3, 1), (1, 2, 1), (2, 3, 2), (2
, 3, 1), (2, 2, 1), (3, 2, 1)]

Press any key to continue . . .


Parquet-backed pyspark doesn't appear to be using partitions to cull when querying - why not?

Question: I have a project which is currently quite small/simple in terms of data volume.  Time-series data with a half-dozen fields, ~1M rows and 22MB per day of data.
I'm still learning the ins and outs of PySpark's use of parquet, but the one thing I feel clear on is that the partition keys are used as a first-pass index-like filter to cull irrelevant data when querying.  If you partition on K and have partition dirs K=A, K=B, K=C, then if K=A appears in the PySpark-SQL query, the subtrees under K=B and K=C should never even be inspected.
My data is partitioned by date, in format YYYY-MM-DD, and sorted by (integer epoch) timestamp before the file was written out. Data is stored on local disk, and the "cluster" is a master and single worker on a development machine.  There is a secondary partition satellite_id having either integer value 1 or two, so every day has two local files.
Querying a small temporal slice of data takes ~300ms on my local deployment with one week of data present in the parquet path.  When a parquet path containing a year of data is used (so ~700 files, total), the query time jumps to 5000ms.  I noticed I'd neglected to include the partition column in my query - whoops!
So I fixed it... and nothing changed.
    @classmethod
    def select(cls, fields: Iterable[str], from_dt: datetime, to_dt: datetime) -> List[pyspark.Row]:
        table_name = 'someTableName'

        spark = get_spark_session()
        table_df = spark.read.parquet(cls.parquet_path)
        table_df.createOrReplaceTempView(table_name)

        fields_str = ', '.join(fields)
        from_rcvtime_intg = cls.dt_to_rcvtime_intg(max(from_dt, timestamp_epoch))
        to_rcvtime_intg = cls.dt_to_rcvtime_intg(to_dt)

        query = f"""
            select {fields_str}, rcv_timestamp
            from {table_name}
            where
                {PARQUET_TEMPORAL_PARTITION_KEY} >= '{from_dt.date().isoformat()}'
                and {PARQUET_TEMPORAL_PARTITION_KEY} <= '{to_dt.date().isoformat()}'
                and rcvtime_intg >= {from_rcvtime_intg}
                and rcvtime_intg <= {to_rcvtime_intg}
        """

        records_df = spark.sql(query)
        return records_df.collect()

Given my understanding of PySpark parquet, with the YYYY-MM-DD partition key present in the query, spark should immediately cull 364 of the available 365 directories (728 of 730 files) before descending into the data files themselves, and the query execution time should therefore be roughly constant despite the ~50x data volume.  So it looks like I'm missing something, and spark's not making use of that "index".
Dumping the query plan yields the following, from which nothing jumps out at me
== Parsed Logical Plan ==
'Project ['ang_accl_z, 'lin_accl_x, 'ang_accl_y, 'rcv_timestamp, 'lin_accl_z, 'satellite_id, 'lin_accl_y, 'ang_accl_x, 'rcv_timestamp]
+- 'Filter ((('temporal_partition_key >= 2023-06-06) AND ('temporal_partition_key <= 2023-06-06)) AND (('rcvtime_intg >= 739324800) AND ('rcvtime_intg <= 739324860)))
   +- 'UnresolvedRelation [GRACEFO_1A_full_resolution], [], false
== Analyzed Logical Plan ==
ang_accl_z: double, lin_accl_x: double, ang_accl_y: double, rcv_timestamp: timestamp, lin_accl_z: double, satellite_id: int, lin_accl_y: double, ang_accl_x: double, rcv_timestamp: timestamp
Project [ang_accl_z#7, lin_accl_x#2, ang_accl_y#6, rcv_timestamp#8, lin_accl_z#4, satellite_id#9, lin_accl_y#3, ang_accl_x#5, rcv_timestamp#8]
+- Filter (((temporal_partition_key#10 >= cast(2023-06-06 as date)) AND (temporal_partition_key#10 <= cast(2023-06-06 as date))) AND ((rcvtime_intg#0L >= cast(739324800 as bigint)) AND (rcvtime_intg#0L <= cast(739324860 as bigint))))
   +- SubqueryAlias gracefo_1a_full_resolution
      +- View (`GRACEFO_1A_full_resolution`, [rcvtime_intg#0L,rcvtime_frac#1L,lin_accl_x#2,lin_accl_y#3,lin_accl_z#4,ang_accl_x#5,ang_accl_y#6,ang_accl_z#7,rcv_timestamp#8,satellite_id#9,temporal_partition_key#10])
         +- Relation [rcvtime_intg#0L,rcvtime_frac#1L,lin_accl_x#2,lin_accl_y#3,lin_accl_z#4,ang_accl_x#5,ang_accl_y#6,ang_accl_z#7,rcv_timestamp#8,satellite_id#9,temporal_partition_key#10] parquet
== Optimized Logical Plan ==
Project [ang_accl_z#7, lin_accl_x#2, ang_accl_y#6, rcv_timestamp#8, lin_accl_z#4, satellite_id#9, lin_accl_y#3, ang_accl_x#5, rcv_timestamp#8]
+- Filter ((isnotnull(temporal_partition_key#10) AND isnotnull(rcvtime_intg#0L)) AND (((temporal_partition_key#10 >= 2023-06-06) AND (temporal_partition_key#10 <= 2023-06-06)) AND ((rcvtime_intg#0L >= 739324800) AND (rcvtime_intg#0L <= 739324860))))
   +- Relation [rcvtime_intg#0L,rcvtime_frac#1L,lin_accl_x#2,lin_accl_y#3,lin_accl_z#4,ang_accl_x#5,ang_accl_y#6,ang_accl_z#7,rcv_timestamp#8,satellite_id#9,temporal_partition_key#10] parquet
== Physical Plan ==
*(1) Project [ang_accl_z#7, lin_accl_x#2, ang_accl_y#6, rcv_timestamp#8, lin_accl_z#4, satellite_id#9, lin_accl_y#3, ang_accl_x#5, rcv_timestamp#8]
+- *(1) Filter ((isnotnull(rcvtime_intg#0L) AND (rcvtime_intg#0L >= 739324800)) AND (rcvtime_intg#0L <= 739324860))
   +- *(1) ColumnarToRow
      +- FileScan parquet [rcvtime_intg#0L,lin_accl_x#2,lin_accl_y#3,lin_accl_z#4,ang_accl_x#5,ang_accl_y#6,ang_accl_z#7,rcv_timestamp#8,satellite_id#9,temporal_partition_key#10] Batched: true, DataFilters: [isnotnull(rcvtime_intg#0L), (rcvtime_intg#0L >= 739324800), (rcvtime_intg#0L <= 739324860)], Format: Parquet, Location: InMemoryFileIndex(1 paths)[file:/nomount/masschange/data_volume_mount/full-resolution], PartitionFilters: [isnotnull(temporal_partition_key#10), (temporal_partition_key#10 >= 2023-06-06), (temporal_parti..., PushedFilters: [IsNotNull(rcvtime_intg), GreaterThanOrEqual(rcvtime_intg,739324800), LessThanOrEqual(rcvtime_int..., ReadSchema: struct<rcvtime_intg:bigint,lin_accl_x:double,lin_accl_y:double,lin_accl_z:double,ang_accl_x:doubl...

Am I misunderstanding how PySpark uses parquet, fundamentally?  Or is there something I need to do to actually leverage partitions during queries, beyond including the relevant field in my Spark-SQL queries?
Answer: Spark uses Hadoop's file system code to get the list of which files and paths are relevant.  It does this before any partition pruning is performed.  The more partitions, and files in them, you have the slower the file search.  In order to mitigate this it's done in a number of threads after the top level partition scan.  Each file in the system is read for stats at least.
On Azure ADLS2 this searching is incredibly slow (performance improvements have been made in the last years though) and made worse by multi-threading as it eats into the maximum concurrent usage of 50k per storage account, so if you have multiple operations even on different files you'll risk throttling and backout by ADSL.
If you are able to use Delta this removes the file search by storing the files (blocks) used in the ledger, so the number of file reads is significantly minimised.
Comment: As OP stated, his data resides locally. Phys plan also confirms this: `...InMemoryFileIndex(1 paths)[**file:**/nomount/masschange/data_volume_mount/full-resolution]...`
Comment: I can confirm, at least, that the scanning doesn't appear to be the issue.  I tested a raw pyarrow implementation of the same filtering logic (though with the satellite partition removed, so half the file count) - 100ms for the week of data, 150ms for the full year.
Comment: Test the actual spark implementation by using [mergeSchema](https://spark.apache.org/docs/latest/sql-data-sources-parquet.html#schema-merging) , without specifying a schema, "load" the parquet and then call and time df.schema() to rule that out on the actual code used.


Summation of divergent series $1-2^p+3^p-4^p+\ldots$

Question: I am trying to obtain that, for $p=1,2,3\ldots$ ,
$$
s_p\equiv\sum_{n=1}^\infty (-1)^{n-1} n^p = \frac{2^{p+1}-1}{p+1}B_{p+1},
$$
where $s_0=1/2$ and $B_m$ are the Bernoulli numbers. The (divergent) series is regularized by means of the Euler summation
$$
\sum_{n=1}^\infty (-1)^{n-1} n^p = \lim_{t\to1^-}\sum_{n=1}^\infty (-1)^{n-1} n^pt^n.
$$
My try: For $|t|<1$,
$$
\sum_{n=1}^\infty (-1)^{n-1} n^pt^n=\left(t\frac{d}{dt}\right)^p \sum_{n=1}^\infty (-1)^{n-1} t^n=\left(t\frac{d}{dt}\right)^p\frac{t}{1+t};
$$
hence, letting $t=e^z$,
$$
s_p=\frac{d^p}{dz^p} \frac{e^z}{1+e^z}\Bigg|_{z=0}.
$$
This is equivalent to formally defining the generating function
$$
G(z) = \sum_{p=0}^\infty s_p \frac{z^p}{p!} = \sum_{n=1}^\infty (-1)^{n-1}\sum_{p=0}^\infty \frac{(nz)^p}{p!}=\sum_{n=1}^\infty (-1)^{n-1} e^{nz} = \frac{e^z}{1+e^z}.
$$
Using the definition of the Euler numbers
$$
\frac{2}{e^z+e^{-z}}=\sum_{m=0}^\infty E_m \frac{z^m}{m!},
$$
we can recast $G(z)$ as follows
$$\begin{aligned}
G(z)=&\ \frac{2}{e^{z/2}+e^{-z/2}}\frac{e^{z/2}}{2}=\sum_{n,m=0}^\infty \frac{1}{2^{n+m+1}}\frac{E_m}{m!n!}z^{n+m}\\
=&\ \sum_{p=0}^\infty \frac{1}{2^{p+1}}\sum_{m=0}^p \binom{p}{m} E_m \frac{z^p}{p!}.
\end{aligned}$$
Hence,
$$
s_p=\frac{1}{2^{p+1}}\sum_{m=0}^p\binom{p}{m}E_m,
$$
which is a bit different at first sight.
As far as I know, the Bernoulli numbers should be
$$
\frac{z}{e^{z}-1}=\sum_{m=0}^\infty B_m\frac{z^m}{m!}
$$
up to sign conventions for $B_1$, so I am unsure on how to proceed.
Comment: I'm not particularly sure about all this, but I usually go here:

$$\sum_{n=0}^\infty(-1)^n(n+1)^p=\sum_{k=0}^\infty\frac1{2^{k+1}}\sum_{n=0}^k\binom nk(-1)^n(n+1)^p=\sum_{k=0}^p\frac1{2^{k+1}}\sum_{n=0}^k\binom nk(-1)^n(n+1)^p$$

Or maybe you should relate it backwards to prove from the zeta function.  `Simply shrugs`.
Comment: Your definition of $s_p$ is not a definition, since the involved series are not convergent. The relation between Bernoulli numbers and the values of the $\eta$ function at odd negative integers just follow from $\zeta(-(2n+1))=\pm\frac{B_{2n+2}}{2n+2}$ and $\eta(s)=(1-2/2^s)\zeta(s)$.
Comment: @JackD'Aurizio I have tried to be a little more explicit about the regularization for the divergent series. Also, the answer I posted is based on the trick needed to show the identity you mentioned so ... thanks!
Answer: We need to reshuffle the generating function as follows:
$$\begin{aligned}
\frac{e^z}{e^z+1}=&\ \frac{1}{1+e^{-z}}=\frac{(e^{-z}-1)^2}{(e^{-z}+1)(e^{-z}-1)^2}=\frac{e^{-2z}-2e^{-z}+1}{(e^{-z}-1)(e^{-2z}-1)}\\
=&\ \frac{1}{e^{-z}-1}-\frac{2}{e^{-2z}-1}=\frac{1}{z}\left(\frac{-2z}{e^{-2z}-1}-\frac{-z}{e^{-z}-1}\right)\\
=&\ \frac{1}{z}\sum_{m=0}^\infty \frac{B_m}{m!}\left[(-2z)^m-(-z)^m\right]\\
=&\ \sum_{p=0}^\infty (-1)^{p+1}\frac{2^{p+1}-1}{p+1} B_{p+1} \frac{z^p}{p!}.
\end{aligned}$$
Hence, for $p=0,1,2\ldots$
$$
s_p=(-1)^{p+1}\frac{2^{p+1}-1}{p+1} B_{p+1},
$$
which also proves the identity
$$
\sum_{m=0}^p \binom{p}{m}E_m =(-1)^{p+1}\frac{4^{p+1}-2^{p+1}}{p+1}B_{p+1}.
$$
For $p=1,2,\ldots$  the factor of $(-1)^{p+1}$ is inessential because odd Bernoulli numbers are zero except $B_1$, so that we may write
$$
s_p=\frac{2^{p+1}-1}{p+1} B_{p+1}.
$$


Components not appearing as intended with GridBagLayout

Question: I'm trying to get GridBagLayout to place 4 panels in a frame, one panel in each quadrant of the frame.  I'm sure that I'm misunderstanding something basic with the layout manager but I'm not sure what.  Here's the code that I have for my GUI:
import java.awt.ScrollPane;
import java.awt.Color;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.FocusEvent;
import java.awt.event.FocusListener;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.awt.Insets;
import java.awt.GridBagLayout;
import java.awt.GridBagConstraints;

import javax.swing.border.*;
import javax.swing.BorderFactory;
import javax.swing.JButton;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTable;
import javax.swing.JTextField;
import javax.swing.ListSelectionModel;
import javax.swing.SwingConstants;
import javax.swing.table.DefaultTableModel;
import javax.swing.table.TableCellRenderer;
import javax.swing.table.TableColumn;

/**
*  GUI to interact with BookList
*/

public class GUI extends JPanel implements ActionListener
{
   //// Main Panel ////
  ////////////////////
  private JPanel mainPanel;

   //// Border ////
  ////////////////
  private Border loweredBorder;

   //// Input Panel ////
  /////////////////////
  private JPanel     inputPanel;

  private JLabel     titleLabel;
  private JTextField titleField;

  private JLabel     authorLabel;
  private JTextField authorField;

  private JLabel     genreLabel;
  private JTextField genreField;

  private JLabel     priceLabel;
  private JTextField priceField;

  private JLabel     reviewLabel;
  private JTextField reviewField;

  private JButton    addBookButton;

   //// Search Panel ////
  //////////////////////
  private JPanel     searchPanel;

  private JLabel     searchLabel;
  private JTextField searchField;

  private JButton    searchButton;

   //// Output Panel ////
  //////////////////////
  private JPanel  outputPanel;

  private JLabel  titleDisplayLabel;
  private JLabel  titleOutputLabel;

  private JLabel  authorDisplayLabel;
  private JLabel  authorOutputLabel;

  private JLabel  genreDisplayLabel;
  private JLabel  genreOutputLabel;

  private JLabel  priceDisplayLabel;
  private JLabel  priceOutputLabel;

  private JLabel  reviewDisplayLabel;
  private JLabel  reviewOutputLabel;

  private JButton editBookButton;
  private JButton deleteBookButton;

   //// Display Panel ////
  //////////////////////////
  private JPanel displayPanel;
  private JScrollPane listPanel;
  private JButton displayButton;

   //// BookList ////
  //////////////////
  private BookList bl;

/**
* Inputs and buttons for interacting with BookList
*/
  public GUI()
  {
    // Instantiate a BookList
    // TODO: Make BookList length a parameter
    bl = new BookList( 5 );

    loweredBorder = BorderFactory.createBevelBorder( BevelBorder.LOWERED );

     //// Instantiate and configure Main Panel ////
    ////////////////////////////////////////////////
    GridBagLayout mainPanelLayout = new GridBagLayout();

    this.setLayout( mainPanelLayout );

     //// Instantiate and configure Input Panel ////
    ///////////////////////////////////////////////
    inputPanel = new JPanel(  );
    GridBagLayout inputPanelGridBag = new GridBagLayout();
    GridBagConstraints inputPanelCons = new GridBagConstraints();

    inputPanelCons.gridx = 0;
    inputPanelCons.gridy = 0;
    inputPanelCons.gridheight = 6;
    inputPanelCons.gridwidth = 2;
    inputPanelCons.weightx = 0.25;
    inputPanelCons.weighty = 0.25;
    inputPanelCons.ipadx = 10;
    inputPanelCons.ipady = 10;
    inputPanelCons.anchor = GridBagConstraints.FIRST_LINE_START;
    inputPanelCons.fill = GridBagConstraints.BOTH;
    inputPanelCons.insets = new Insets( 5, 5, 5, 5);

    inputPanelGridBag.setConstraints( inputPanel, inputPanelCons );

    inputPanel.setBorder(
      BorderFactory.createTitledBorder( loweredBorder,
                                        "Add/Edit Book") );

    inputPanel.setLayout( inputPanelGridBag );

    // Title Input Label
    titleLabel = new JLabel( "Title:", JLabel.TRAILING );

    GridBagConstraints titleLabelCons = new GridBagConstraints();
    titleLabelCons.gridx = 0;
    titleLabelCons.gridy = 0;
    titleLabelCons.ipadx = 10;
    titleLabelCons.ipady = 10;
    titleLabelCons.insets = new Insets( 5, 5, 5, 5);
    inputPanelGridBag.setConstraints( titleLabel, titleLabelCons );

    inputPanel.add( titleLabel );

    // Title Input Field
    titleField = new JTextField( 16 );
    titleLabel.setLabelFor( titleField );

    GridBagConstraints titleFieldCons = new GridBagConstraints();
    titleFieldCons.gridx = 1;
    titleFieldCons.gridy = 0;
    titleFieldCons.ipadx = 10;
    titleFieldCons.ipady = 10;
    titleFieldCons.insets = new Insets( 5, 5, 5, 5);
    inputPanelGridBag.setConstraints( titleField, titleFieldCons );

    inputPanel.add( titleField );

    // Author Input Label
    authorLabel = new JLabel( "Author:", JLabel.TRAILING );

    GridBagConstraints authorLabelCons = new GridBagConstraints();
    authorLabelCons.gridx = 0;
    authorLabelCons.gridy = 1;
    authorLabelCons.ipadx = 10;
    authorLabelCons.ipady = 10;
    authorLabelCons.insets = new Insets( 5, 5, 5, 5);
    inputPanelGridBag.setConstraints( authorLabel, authorLabelCons );

    inputPanel.add( authorLabel );

    // Author Input Field
    authorField = new JTextField( 16 );

    GridBagConstraints authorFieldCons = new GridBagConstraints();
    authorFieldCons.gridx = 1;
    authorFieldCons.gridy = 1;
    authorFieldCons.ipadx = 10;
    authorFieldCons.ipady = 10;
    authorFieldCons.insets = new Insets( 5, 5, 5, 5);
    inputPanelGridBag.setConstraints( authorField, authorFieldCons );

    authorLabel.setLabelFor( authorField );
    inputPanel.add( authorField );

    // Genre Input Label
    genreLabel = new JLabel( "Genre:", JLabel.TRAILING );

    GridBagConstraints genreLabelCons = new GridBagConstraints();
    genreLabelCons.gridx = 0;
    genreLabelCons.gridy = 2;
    genreLabelCons.ipadx = 10;
    genreLabelCons.ipady = 10;
    genreLabelCons.insets = new Insets( 5, 5, 5, 5);
    inputPanelGridBag.setConstraints( genreLabel, genreLabelCons );

    inputPanel.add( genreLabel );

    // Genre Input Field
    genreField = new JTextField( 16 );

    GridBagConstraints genreFieldCons = new GridBagConstraints();
    genreFieldCons.gridx = 1;
    genreFieldCons.gridy = 2;
    genreFieldCons.ipadx = 10;
    genreFieldCons.ipady = 10;
    genreFieldCons.insets = new Insets( 5, 5, 5, 5);
    inputPanelGridBag.setConstraints( genreField, genreFieldCons );

    genreLabel.setLabelFor( genreField );
    inputPanel.add( genreField );

    // Price Input Label
    priceLabel = new JLabel( "Price:", JLabel.TRAILING );

    GridBagConstraints priceLabelCons = new GridBagConstraints();
    priceLabelCons.gridx = 0;
    priceLabelCons.gridy = 3;
    priceLabelCons.ipadx = 10;
    priceLabelCons.ipady = 10;
    priceLabelCons.insets = new Insets( 5, 5, 5, 5);
    inputPanelGridBag.setConstraints( priceLabel, priceLabelCons );

    inputPanel.add( priceLabel );

    // Price Input Field
    priceField = new JTextField( 16 );

    GridBagConstraints priceFieldCons = new GridBagConstraints();
    priceFieldCons.gridx = 1;
    priceFieldCons.gridy = 3;
    priceFieldCons.ipadx = 10;
    priceFieldCons.ipady = 10;
    priceFieldCons.insets = new Insets( 5, 5, 5, 5);
    inputPanelGridBag.setConstraints( priceField, priceFieldCons );

    priceLabel.setLabelFor( priceField );
    inputPanel.add( priceField );

    // Review Input Label
    reviewLabel = new JLabel( "Review:", JLabel.TRAILING );

    GridBagConstraints reviewLabelCons = new GridBagConstraints();
    reviewLabelCons.gridx = 0;
    reviewLabelCons.gridy = 4;
    reviewLabelCons.ipadx = 10;
    reviewLabelCons.ipady = 10;
    reviewLabelCons.insets = new Insets( 5, 5, 5, 5);
    inputPanelGridBag.setConstraints( reviewLabel, reviewLabelCons );

    inputPanel.add( reviewLabel );

    // Review Input Field
    reviewField = new JTextField( 16 );

    GridBagConstraints reviewFieldCons = new GridBagConstraints();
    reviewFieldCons.gridx = 1;
    reviewFieldCons.gridy = 4;
    reviewFieldCons.ipadx = 10;
    reviewFieldCons.ipady = 10;
    reviewFieldCons.insets = new Insets( 5, 5, 5, 5);
    inputPanelGridBag.setConstraints( reviewField, reviewFieldCons );

    reviewLabel.setLabelFor( reviewField );
    inputPanel.add( reviewField );

    // Add Book Button
    addBookButton = new JButton( "Add" );

    GridBagConstraints addBookButtonCons = new GridBagConstraints();
    addBookButtonCons.gridx = 1;
    addBookButtonCons.gridy = 5;
    addBookButtonCons.ipadx = 10;
    addBookButtonCons.ipady = 10;
    addBookButtonCons.insets = new Insets( 5, 5, 5, 5);
    inputPanelGridBag.setConstraints( addBookButton, addBookButtonCons );

    inputPanel.add( addBookButton );

    // Add Book Button Event Listener
    addBookButton.addActionListener( this );

    // Add `inputPanel` to `mainPanel`
    this.add( inputPanel );

     //// List Panel instantiation and configuration ////
    /////////////////////////////////////////////////////
    displayPanel = new JPanel();

    GridBagLayout displayPanelGridBag = new GridBagLayout();
    GridBagConstraints displayPanelCons = new GridBagConstraints();

    displayPanelCons.gridx = 0;
    displayPanelCons.gridy = 1;
    displayPanelCons.gridheight = 2;
    displayPanelCons.gridwidth = 1;
    displayPanelCons.weightx = 0.25;
    displayPanelCons.weighty = 0.25;
    displayPanelCons.ipadx = 10;
    displayPanelCons.ipady = 10;
    displayPanelCons.anchor = GridBagConstraints.LAST_LINE_START;
    displayPanelCons.fill = GridBagConstraints.BOTH;
    displayPanelCons.insets = new Insets( 5, 5, 5, 5 );

    displayPanelGridBag.setConstraints( displayPanel, displayPanelCons );

    displayPanel.setBorder(
      BorderFactory.createTitledBorder( loweredBorder,
                                        "Book List") );

    displayPanel.setLayout( displayPanelGridBag );

    // Separate panel for ScrollPane
    listPanel = new JScrollPane();

    GridBagConstraints listPanelCons = new GridBagConstraints();
    listPanelCons.gridx = 0;
    listPanelCons.gridy = 0;
    listPanelCons.ipadx = 10;
    listPanelCons.ipady = 10;
    listPanelCons.fill = GridBagConstraints.BOTH;
    listPanelCons.insets = new Insets( 5, 5, 5, 5 );

    displayPanelGridBag.setConstraints( listPanel, listPanelCons );

    JTable listTable = new JTable();

    listTable.setSelectionMode( ListSelectionModel.SINGLE_SELECTION );

    String[] colHeaders = { "Title", "Author", "Genre", "Price", "Review" };
    listTable.setModel(
      new DefaultTableModel( colHeaders, 0 )
      {
        boolean[] colEditables = { false,
                                   false,
                                   false,
                                   false,
                                   false };

        public boolean isCellEditable( int row, int col )
      {
        return colEditables[ col ];
      }
    });

    listPanel.add( listTable );
    displayPanel.add( listPanel );

    displayButton = new JButton( "Display" );

    GridBagConstraints displayButtonCons = new GridBagConstraints();
    displayButtonCons.gridx = 0;
    displayButtonCons.gridy = 1;
    displayButtonCons.ipadx = 10;
    displayButtonCons.ipady = 10;
    displayButtonCons.insets = new Insets( 5, 5, 5, 5 );

    displayPanelGridBag.setConstraints( displayButton, displayButtonCons );

    displayButton.addActionListener( this );

    displayPanel.add( displayButton );

    this.add( displayPanel );

     //// Search Panel instantiation and configuration ////
    //////////////////////////////////////////////////////
    searchPanel = new JPanel();

    GridBagLayout searchPanelGridBag = new GridBagLayout();
    GridBagConstraints searchPanelCons = new GridBagConstraints();

    searchPanelCons.gridheight = 2;
    searchPanelCons.gridwidth = 2;
    searchPanelCons.weightx = 0.25;
    searchPanelCons.weighty = 0.25;
    searchPanelCons.gridx = 1;
    searchPanelCons.gridy = 0;
    searchPanelCons.ipadx = 10;
    searchPanelCons.ipady = 10;
    searchPanelCons.anchor = GridBagConstraints.FIRST_LINE_END;
    searchPanelCons.fill = GridBagConstraints.BOTH;
    searchPanelCons.insets = new Insets( 5, 5, 5, 5);

    searchPanelGridBag.setConstraints( searchPanel, searchPanelCons );
    searchPanel.setBorder(
      BorderFactory.createTitledBorder( loweredBorder,
                                        "Search for Book" ) );
    searchPanel.setLayout( searchPanelGridBag );

    // Search Input Label
    searchLabel = new JLabel( "Search:", JLabel.TRAILING );

    GridBagConstraints searchLabelCons = new GridBagConstraints();
    searchLabelCons.gridx = 0;
    searchLabelCons.gridy = 0;
    searchLabelCons.ipadx = 10;
    searchLabelCons.ipady = 10;
    searchLabelCons.insets = new Insets( 5, 5, 5, 5);
    searchPanelGridBag.setConstraints( searchLabel, searchLabelCons );

    searchPanel.add( searchLabel );

    // Search Input Field
    searchField = new JTextField( 16 );
    searchLabel.setLabelFor( searchField );

    GridBagConstraints searchFieldCons = new GridBagConstraints();
    searchFieldCons.gridx = 1;
    searchFieldCons.gridy = 0;
    searchFieldCons.ipadx = 10;
    searchFieldCons.ipady = 10;
    searchFieldCons.insets = new Insets( 5, 5, 5, 5);
    searchPanelGridBag.setConstraints( searchField, searchFieldCons );

    searchPanel.add( searchField );

    // Search Button
    searchButton = new JButton( "Search" );
    searchButton.addActionListener( this );

    GridBagConstraints searchButtonCons = new GridBagConstraints();
    searchButtonCons.gridx = 1;
    searchButtonCons.gridy = 1;
    searchButtonCons.ipadx = 10;
    searchButtonCons.ipady = 10;
    searchFieldCons.insets = new Insets( 5, 5, 5, 5 );
    searchPanelGridBag.setConstraints( searchButton, searchButtonCons );

    searchPanel.add( searchButton );

    this.add( searchPanel );

     //// Output Panel instantiation and configuration ////
    //////////////////////////////////////////////////////
    outputPanel = new JPanel();

    GridBagLayout outputPanelGridBag = new GridBagLayout();
    GridBagConstraints outputPanelCons = new GridBagConstraints();

    outputPanelCons.gridx = 1;
    outputPanelCons.gridy = 1;
    outputPanelCons.gridheight = 6;
    outputPanelCons.gridwidth = 2;
    outputPanelCons.weightx = 0.25;
    outputPanelCons.weighty = 0.25;
    outputPanelCons.ipadx = 10;
    outputPanelCons.ipady = 10;
    outputPanelCons.anchor = GridBagConstraints.LAST_LINE_END;
    outputPanelCons.fill = GridBagConstraints.BOTH;
    outputPanelCons.insets = new Insets( 5, 5, 5, 5 );
    outputPanelGridBag.setConstraints( outputPanel, outputPanelCons );

    outputPanel.setBorder(
      BorderFactory.createTitledBorder( loweredBorder,
                                        "Book Information" ) );
    outputPanel.setLayout( outputPanelGridBag );

    // Title Label
    titleDisplayLabel = new JLabel( "Title:", JLabel.TRAILING );

    GridBagConstraints titleDisplayCons = new GridBagConstraints();
    titleDisplayCons.gridx = 0;
    titleDisplayCons.gridy = 0;
    titleDisplayCons.ipadx = 10;
    titleDisplayCons.ipady = 10;
    titleDisplayCons.insets = new Insets( 5, 5, 5, 5 );
    outputPanelGridBag.setConstraints( titleDisplayLabel, titleDisplayCons );

    outputPanel.add( titleDisplayLabel );

    // Title Output
    titleOutputLabel = new JLabel( "", JLabel.LEADING );

    GridBagConstraints titleOutputCons = new GridBagConstraints();
    titleOutputCons.gridx = 1;
    titleOutputCons.gridy = 0;
    titleOutputCons.ipadx = 10;
    titleOutputCons.ipady = 10;
    titleOutputCons.insets = new Insets( 5, 5, 5, 5 );
    outputPanelGridBag.setConstraints( titleOutputLabel, titleOutputCons );

    outputPanel.add( titleOutputLabel );

    // Author Label
    authorDisplayLabel = new JLabel( "Author:", JLabel.TRAILING );

    GridBagConstraints authorDisplayCons = new GridBagConstraints();
    authorDisplayCons.gridx = 0;
    authorDisplayCons.gridy = 1;
    authorDisplayCons.ipadx = 10;
    authorDisplayCons.ipady = 10;
    authorDisplayCons.insets = new Insets( 5, 5, 5, 5 );
    outputPanelGridBag.setConstraints( authorDisplayLabel, authorDisplayCons );

    outputPanel.add( authorDisplayLabel );

    // Author Output
    authorOutputLabel = new JLabel( "", JLabel.LEADING );

    GridBagConstraints authorOutputCons = new GridBagConstraints();

    authorOutputCons.gridx = 1;
    authorOutputCons.gridy = 1;
    authorOutputCons.ipadx = 10;
    authorOutputCons.ipady = 10;
    authorOutputCons.insets = new Insets( 5, 5, 5, 5 );
    outputPanelGridBag.setConstraints( authorOutputLabel, authorOutputCons );

    outputPanel.add( authorOutputLabel );

    // Genre Label
    genreDisplayLabel = new JLabel( "Genre:", JLabel.TRAILING );

    GridBagConstraints genreDisplayCons = new GridBagConstraints();
    genreDisplayCons.gridx = 0;
    genreDisplayCons.gridy = 2;
    genreDisplayCons.ipadx = 10;
    genreDisplayCons.ipady = 10;
    genreDisplayCons.insets = new Insets( 5, 5, 5, 5 );
    outputPanelGridBag.setConstraints( genreDisplayLabel, genreDisplayCons );

    outputPanel.add( genreDisplayLabel );

    // Genre Output
    genreOutputLabel = new JLabel( "", JLabel.LEADING );

    GridBagConstraints genreOutputCons = new GridBagConstraints();
    genreOutputCons.gridx = 1;
    genreOutputCons.gridy = 2;
    genreOutputCons.ipadx = 10;
    genreOutputCons.ipady = 10;
    genreOutputCons.insets = new Insets( 5, 5, 5, 5 );
    outputPanelGridBag.setConstraints( genreOutputLabel, genreOutputCons );

    outputPanel.add( genreOutputLabel );

    // Price Label
    priceDisplayLabel = new JLabel( "Price:", JLabel.TRAILING );

    GridBagConstraints priceDisplayCons = new GridBagConstraints();
    priceDisplayCons.gridx = 0;
    priceDisplayCons.gridy = 3;
    priceDisplayCons.ipadx = 10;
    priceDisplayCons.ipady = 10;
    priceDisplayCons.insets = new Insets( 5, 5, 5, 5 );
    outputPanelGridBag.setConstraints( priceDisplayLabel, priceDisplayCons );

    outputPanel.add( priceDisplayLabel );

    // Price Output
    priceOutputLabel = new JLabel( "", JLabel.LEADING );

    GridBagConstraints priceOutputCons = new GridBagConstraints();
    priceOutputCons.gridx = 1;
    priceOutputCons.gridy = 3;
    priceOutputCons.ipadx = 10;
    priceOutputCons.ipady = 10;
    priceOutputCons.insets = new Insets( 5, 5, 5, 5 );
    outputPanelGridBag.setConstraints( priceOutputLabel, priceOutputCons );

    outputPanel.add( priceOutputLabel );

    // Review Label
    reviewDisplayLabel = new JLabel( "Review:", JLabel.TRAILING );

    GridBagConstraints reviewDisplayCons = new GridBagConstraints();
    reviewDisplayCons.gridx = 0;
    reviewDisplayCons.gridy = 4;
    reviewDisplayCons.ipadx = 10;
    reviewDisplayCons.ipady = 10;
    reviewDisplayCons.insets = new Insets( 5, 5, 5, 5 );
    outputPanelGridBag.setConstraints( reviewDisplayLabel, reviewDisplayCons );

    outputPanel.add( reviewDisplayLabel );

    // Review Output
    reviewOutputLabel = new JLabel( "", JLabel.LEADING );

    GridBagConstraints reviewOutputCons = new GridBagConstraints();
    reviewOutputCons.gridx = 1;
    reviewOutputCons.gridy = 4;
    reviewOutputCons.ipadx = 10;
    reviewOutputCons.ipady = 10;
    reviewOutputCons.insets = new Insets( 5, 5, 5, 5 );
    outputPanelGridBag.setConstraints( reviewOutputLabel, reviewOutputCons );

    outputPanel.add( reviewOutputLabel );

    // Edit Button
    editBookButton = new JButton( "Edit" );

    GridBagConstraints editButtonCons = new GridBagConstraints();
    editButtonCons.gridx = 0;
    editButtonCons.gridy = 5;
    editButtonCons.ipadx = 10;
    editButtonCons.ipady = 10;
    editButtonCons.insets = new Insets( 5, 5, 5, 5 );
    outputPanelGridBag.setConstraints( editBookButton, editButtonCons );

    outputPanel.add( editBookButton );

    editBookButton.addActionListener( this );

    // Delete Button
    deleteBookButton = new JButton( "Delete" );

    GridBagConstraints deleteButtonCons = new GridBagConstraints();
    deleteButtonCons.gridx = 1;
    deleteButtonCons.gridy = 5;
    deleteButtonCons.ipadx = 10;
    deleteButtonCons.ipady = 10;
    deleteButtonCons.insets = new Insets( 5, 5, 5, 5 );
    outputPanelGridBag.setConstraints( deleteBookButton, deleteButtonCons );

    outputPanel.add( deleteBookButton );

    deleteBookButton.addActionListener( this );

    this.add( outputPanel );

  }

  public void actionPerformed(ActionEvent e)
  {

  }

}

And here's how the window looks when I compile and run the application:

I know that I don't have anything hooked up to display data in the JTable in displayPanel, but shouldn't the headers be appearing also?
If any clarification is needed let me know, I'll be thinking of what else would be useful and make some updates as needed.
Comment: You serioulsy expect someone to look through that mess? You should factor out the panels into self contained classes - that will reduce the clutter in each panel to whats related to that panel; you can then test each panel layout separately. Its will be obvious where it goes wrong once you have that.
Answer: Here you are replacing the ViewportView of the JScrollPane with the table.
listPanel.add( listTable );

Replace with
listPanel.setViewportView(listTable);

Read: JScrollPane.


Custom field: process submitted before storing

Question: I've created custom field type and widget plugins in D8.
I am presenting an element in my widget as checkboxes, but I need to transform the resulting array into text delimited by pipes. i.e. a|b|c.
How would I approach this in the field widget?
Comment: Wouldn't this be the job of the field formatter?
Comment: No, that is for display purposes.
Answer: messageFormValues in the widget class did the job.
class MyDefaultWidget extends WidgetBase {
  ...
  /**
   * {@inheritdoc}
   */
  public function massageFormValues(array $values, array $form, FormStateInterface $form_state) {
    // Change the format of $item['sections'] from array to pipe delimited string.
    foreach ($values as &$item) {
      $sections = [];
      if (is_array($item['sections'])) {
        foreach ($item['sections'] as $s) {
          if ($s !== 0) {
            $sections[] = $s;
          }
        }
      }
      $item['sections'] = implode('|', $sections);
    }
    return $values;
  }
  ...
}


Android: Auto Rotate not working after setRequestedOrientation

Question: I have a video player in which I have two features:

If the auto-rotate is disabled and when the user clicks on fullscreen button I force the orientation to go in landscape view using setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_SENSOR_LANDSCAPE) and back to portrait view when fullscreen is exited.
I have overridden the onConfigurationChanged to detect the change in orientation when the auto-rotate feature is enabled by user and change the activity view according to the orientation.

Now the problem with this setup is that if user start the activity and goes in fullscreen and setRequestedOrientation get invoked once, later when auto-rotate is enabled, the activity doesn't receive the orientation changes and the onConfigurationChanged doesn't get called.
I read here (https://stackoverflow.com/a/6109206/5167868) that they wont work simultaneously.
I would like to know if there a way of implementing both as I have seen players like MX Player do this in their app.
Comment: that might be because you force portrait orientation after exitting fullscreen. Try setting not portrait, but automatical orientation: `SCREEN_ORIENTATION_SENSOR`
Comment: But I want it to be in Portrait Orientation if the auto-rotate is disabled.
Comment: Sorry I wasnt clear earlier and I edited the question. I meant after the user enables auto-rotation, the onConfigurationChanged is not called.
Comment: check [http://stackoverflow.com/questions/22848222/toggling-fullscreen-orientation-like-youtube?answertab=active#tab-top](http://stackoverflow.com/questions/22848222/toggling-fullscreen-orientation-like-youtube?answertab=active#tab-top)
Comment: @SuhasShelar did you find a solution?
Answer: After you fix the orientation of the screen by using setRequestedOrientation(), Auto Rotate feature won't work. So to make it work, you may do something like this:
After you set your orientation using: setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_SENSOR_LANDSCAPE)
Call this:
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED)
This shall make the auto rotate to work again!
Comment: Doesn't work, my screen changes to landscape and then back to portrait immediately.


How can I publish to play store the x86 and ARM apks of my cordova-crosswalk app?

Question: My app is developped/published with Cordova and Crosswalk. Crosswalk generates an apk for ARM cpus and another one for x86 cpus.
At the moment, when I upload my ARM apk to the play store and then try to upload the x86 one, it prevents me from doing so and display a message that says that I cannot have two apk with the same version code.
It seems it's possible to upload on the play store multiple apk files for the same version of an application byt filtering the devices targetted by each apk file.
However, it seems to require the use of an "Application.mk" file that the Cordova project structure doesn't seem to have by default.
How can I include an Application.mk file within my apks so that both the ARM and the x86 with the same version code will be uploadable to the Play store ?
Answer: It's absolutily possible.
This feature receve the name of:  Multiple APK
You don't need to use the 'Application.mk'
The process is simple:

In Developer Console, switch to Advanced Mode (click the Switch to advanced mode button at the top right of the APK tab - note that you must have uploaded at least one APK for that button to appear)
Upload the two APK
Publish!

There's some rules to use multiple APK, but if you use the files generated by cordova crosswalk, you have nothing to worry about.
The problem that you described with version code, happens beacuse each app must have a different version code. In my case, I use ionic framework (extends cordova) and in the build process, it generated a diferent version code por each apk, so I had no problem. If it not happens for you, you can try to change de android:versionCode directly on the AndroidManifest.xml file.
Here is how my manifest looks like:
<manifest
  android:hardwareAccelerated="true"
  android:versionCode="102"
  android:versionName="0.1.2"
  package="br.org.yyyyyyy.xxxxxxxxxx"
  xmlns:android="http://schemas.android.com/apk/res/android">

In my case, the arm7 apk, the

android:versionCode="102"

And  in x86 apk the

android:versionCode="104"

References:
Android Multiple APKs DOC
Maintaining Multiple APKs DOC
Answer: I`m doing simple way. Example your main v code is 102, so you build first arm with 102 v code, and upload. Until upload runs, you can go change v code in manifest and in build grade to 103 and build another one x86. Easy and simple.
Answer: I think things have changed in the past year. I used the same version code and uploaded both apks (one at a time - in the normal way). Google Play auto-detected that they were targeted to different native platforms, and allowed both to be entered into production.
Answer: The cordova-crosswalk doc instructs how to make an apk that works for both arm and x86. The problem is that it makes a huge apk.
If you really want to make two apks, you can try (sorry not tested yet) to create the Application.mk file in the folder platforms/android/jni
For arm you'd put this line in Application.mk :
APP_ABI := armeabi armeabi-v7a

And for intel x86 :
APP_ABI := x86

And you have to change AndroidManifest.xml to have a different version for each platform (following the instructions in the link you provided).
Be carefull, if you run cordova build android again, it will probably replace all the content of platforms/android, and your changes will be lost.
To build the project use
platforms\android\cordova\build.bat -release

instead of
cordova build android --release


Probability of getting off at the bus stop

Question:
6 stops on the line, and a car with 4 passengers. Assume they are equally likely to get off at any stop. What is the probability that A $2$ passengers get off stop 2, and $2$ get off stop 4? B $2$ get off stop 1, and $2$ get of at another stop (but they get off at the same stop as each other?)

A
I get $1/81$ which is wrong?
B I get $5/6^4$ which is also wrong?
Why are both of these wrong?
Comment: I don't think anyone can say **why** these answers are wrong unless you explain why you thought they are right.  If you just want the correct answers, that's a different question.
Comment: @ Shraddheya Shendre -- By addition of mutiually exclusive events, the answer for (B) should be 5 times the answer for (A).
Comment: If they are equally likely to get off at any stop, then shouldn't the answer for  **A** and **B** be the same?
Comment: Yes, I see what you are saying. My bad.
Answer: For both the parts, the total number of possible ways by which the passengers can exit is $6^4$.
For part A,
the ways by which $2$ passengers can be grouped is $\binom{4}{2}$ (and the other $2$ are automatically grouped so there's nothing else to do). So the number of ways in which the exiting of passengers can be done is $\binom{4}{2}$.
So the required probability in part A is $$\frac{\binom{4}{2}}{6^4}$$
For part B,
the number of ways of grouping remains same:  $\binom{4}{2}$; but now the exit stop can be assigned in $5$ ways (one group exits at stop $1$ and other can exit on remaining $5$ stops). So the required probability is $$\frac{5 \times \binom{4}{2}}{6^4}$$
Comment: Since, as you say, the other $2$ passengers are automatically grouped, this means that you're double counting.
Comment: So you are saying that I shouldn't count for the switching of the groups (and hence not multiply by $2$)?
Comment: Right -- don't multiply by 2. The ordered 4-tuple is completely determined once you select the two passengers who get off at stop 2.
Comment: Yes, I corrected the answer. Thanks for pointing out the mistake.
Comment: No problem -- it looks fine now.


How to install/use a local version of package using Stack?

Question: The situation is, I am trying to install Netwire using Stack. However, there is a problem in the latest netwire 5.0.1, as reported by dhobbs: http://hub.darcs.net/ertes/netwire/issue/13
Since I don't know when the problem will ever be fixed, I downloaded the repo and made the change myself. However, I don't understand how to install such a locally patched version. stack install does not install that into ~/.stack. Does anyone have an idea?
Update
Now I am developing some other libraries using Stack. How do I make another project use that libraries? Hard coding a relative path looks incredibly ugly.
Answer: So you have a project where you want to use your locally patched Netwire version and in your project you have a stack.yml, as an example:
flags: {}
packages:
- '.'
extra-deps: {}
resolver: lts-3.7

You also have an dependency on netwire declared in your cabal file.
To use you patched Netwire in this project of yours you simply put the patched Netwire package in a subdirectory of your project, perhaps called netwire, and update your stack.yml as such:
flags: {}
packages:
- '.'
- netwire
extra-deps: {}
resolver: lts-3.7

Now stack build will build your project with the patched Netwire version.
You can also put the modified source online (if the license permits) and refer to the source using either a tarball URL
- https://example.com/netwire.tar.gz

or a git repository and commit reference:
- location:
    git: firstname.lastname@example.com/netwire
    commit: 6a86ee32e5b869a877151f74064572225e1a0398

(Check out the documentation for more info: https://docs.haskellstack.org/en/stable/yaml_configuration/#packages-and-extra-deps)
Comment: I know this method. However, I would like to put the netwire library at a more convenient place, isolated from the source. Doing what you said makes me feel like compiling a bunch of softwares under /usr and keep the sources right there.
Comment: You can specify a git location as a package. See the docs on stack.yaml. That way you don't need to put the source in your project's directory. Sorry for no links, I'm on my phone.
Comment: You can get around needing to have netwire as a subdirectory with a symlink. Just put it wherever you want and drop a symlink to it into your package. It's kind of a hack, but it will get the job done.
Comment: Does that mean I have to keep the source then? I think it is better to just take the libraries
Comment: AFAIK stack is a tool for building collections of packages from _source_, with the ability to cache some of the build artifiacts (the ones that are part of the Stackage nightlies/lts-s). Since Netwire is not part of Stackage I don't think you have any hope of it ending up in the cache.
Comment: Or say, I'd like it if I use `stack ghci` anywhere, I can just import `Control.Wire`
Comment: I'm not 100% but I don't think that is a supported use case.
Comment: OK, I guess for now I will just find a nice place to put the sources.
Comment: "You can also put the modified source online (if the license permits) and refer to the source using either a tarball URL" It seems that "packages" does not support this syntax in "stack.yaml"? it prompt InvalidAbsDir.


Change any number of delimiters in found pattern with sed

Question: I want to change every . to  @.@  with sed, but only if the . is enclosed with numbers.
For example:
This sentence ends with a dot. 1.2.3
Dot. 188.8.131.52.5 Dot.

The goal:
This sentence ends with a dot. 1 @.@ 2 @.@ 3
Dot. 1 @.@ 2 @.@ 3 @.@ 4 @.@ 5 Dot.

The pattern could contain any number of integers.
I tried:
sed -E 's/([0-9]+)\.([0-9]+)/\1 @\.@ \2/g'

but it only works for the first two number in the pattern.
Comment: IMHO, tags of perl, regex, awk were added by OP in original question itself, along with it answers are also given as per it(it includes all mentioned tags answers here), thank you.
Answer: For the repeated pattern (number-dot-number-dot-number...) that substitution doesn't work because the number following the dot is
"consumed" and so the engine moved along the string, so the next character it sees is a dot, not the needed num-dot-num  pattern.
One solution is to use lookarounds,† which are "zero-width" assertions, so with which the engine doesn't consume the match and doesn't move along, but it merely "looks" from its "spot" between characters to assert that the pattern (ahead or behind) matches, so to say
s/ (?<=[0-9]) \. (?=[0-9]) / @.@ /gx;

For a testable example (in Perl, as tagged)
perl -wE'$_=q(Dot. 126.96.36.199.5 Dot.); say; s/(?<=[0-9])\.(?=[0-9])/ @.@ /g; say'

which prints

Dot. 220.127.116.11.5 Dot.
Dot. 1 @.@ 2 @.@ 3 @.@ 4 @.@ 5 Dot.

But the lookbehind won't work with a "number" that consists of more than one digit, since then we'd need [0-9]+ which has variable and unlimited length, whiat lookbehinds can't (yet) do.
If it is indeed possible to have multi-digit numbers in your case, then the number before the . need be captured -- this still works with the number before the dot -- and then put back
s/([0-9]+)\.(?=[0-9])/$1 @.@ /g;

This can be done anyway, of course, even if it's all always single digits;  i used lookbehind originally only for the symmetry with the other side (needing a lookahead)

†  In a tool that supports them, which in my understanding sed isn't.  (Thanks to comments by potong and Ed Morton for informing of that) I still offer this solution since Perl is one of the tagged languages.
Comment: It should be noted that these solutions will not work with the majority of sed versions.
Comment: @potong  Thanks for that comment, I edited the answer to state it explicitly.  I got a bit tired of the guessing game of whether they want this language or that, between what is mentioned in text/title and what is tagged.  So I take it that if it's in the tag it's an equal target. (This can be debated of course.)  I do appreciate an actual straigth-up `sed` answer, as by tshiono and Ed (upvoted), but I take other tagged languages as valid as well.  (I understand that you didn't challenge that, just saying...)
Answer: As for the 1st line, the regex matches 1.2 for the 1st trial.
The next pattern match starts with the character . just after the
previous match then it fails.
With sed please try:
sed -E '
:l
s/([[:digit:]])\.([[:digit:]])/\1 @.@ \2/
t l
' file

which iterates the pattern match from the start of the string.
As you are adding perl in the tag, here is an alternative with perl:
perl -pe 's/(?<=\d)\.(?=\d)/ @.@ /g' file

Comment: An alternative `sed -E 's/([0-9])\.([0-9])/\1 @.@ \2/g;s//\1 @.@ \2/g' file` since those substitutions not matched in a first pass will be in the second.
Comment: You should mention that will only work in a sed that has a `-E` argument, e.g. GNU sed and OSX/BSD sed, but idk if the script itself would would work in a non-GNU sed since anything more than s/old/new is usually GNU-specific.
Answer: With your shown samples, please try following. Written and tested in GNU awk.
awk -v RS='([0-9]+.)+[0-9]+' '{gsub(/\./," @.@ ",RT);ORS=RT;print}' Input_file

Explanation: Simply making record separator as digits(one or more occurrences) with dot(.)'s one or more occurrences followed with 1 or more digits occurrences. Then substituting dot coming at last with @.@ as per OP's request, resetting ORS and printing that line then. To get more info on awk you could check man awk page too.
Answer: Using any sed in any shell on every Unix box:
$ sed 's/\([0-9]\)\.\([0-9]\)/\1 @.@ \2/g; s/\([0-9]\)\.\([0-9]\)/\1 @.@ \2/g' file
This sentence ends with a dot. 1 @.@ 2 @.@ 3
Dot. 1 @.@ 2 @.@ 3 @.@ 4 @.@ 5 Dot.

You need 2 passes of the input because given input of 1.2.3 only 1.2 will be matched by the first pass of [0-9]\.[0-9], the 2.3 won't be recognized in that pass because the 2 was already consumed by the first match so all that's left of the input in that first pass is .3, you need the 2nd pass (now against 1 @.@ 2.3) to match 2.3.
Answer: Here is a POSIX awk solution:
awk '{while (match($0, /[0-9]\.[0-9]/))
   $0 = substr($0, 1, RSTART) " @.@ " substr($0, RSTART+2)} 1' file

This sentence ends with a dot. 1 @.@ 2 @.@ 3
Dot. 1 @.@ 2 @.@ 3 @.@ 4 @.@ 5 Dot.


Limiting the size of a HTTP post request on JBoss

Question: I am using Jboss 4.2.3 as an appserver. Is there a way to limit the size of the HTTP Post request accepted by JBoss? I want to limit the size to avoid DOS attacks.
I already sat maxHttpHeaderSize and maxPostSize in the server.xml, but neither of them seem to make any difference.
Answer: maxPostSize defines how big a POST can get before Tomcat will "automatically" parse it, whatever that means.
If you're doing this for security reasons, you need to think twice about how you do it. A DOS attack isn't going to conveniently announce its size as an HTTP request header, it's just going to send data until your server falls over.
You could check the Content-Length header of the request, and reject it immediately if it's not present, or too big, but you run the risk of rejecting genuine clients that don't supply the header, which many won't.
Otherwise, you're just going to have to read the request data until it crosses a threshold, and then reject it.
Either way, the container can't help you much.
Comment: +1 and a DDOS attack is not only sending large data. It's also a happening of thousands of simultaneous requests at once.
Answer: For Jboss you should configure in configuration file (eg: standalone-full.xml) like this:
with max-post-size="26214400" means 25MB
<subsystem xmlns="urn:jboss:domain:undertow:3.1">
        <buffer-cache name="default"/>
        <server name="default-server">
            <http-listener name="default" max-post-size="26214400" socket-binding="http" redirect-socket="https"/>
            <host name="default-host" alias="localhost">
                <location name="/" handler="welcome-content"/>
                <filter-ref name="server-header"/>
                <filter-ref name="x-powered-by-header"/>
            </host>
        </server>
        <servlet-container name="default">
            <jsp-config/>
            <websockets/>
        </servlet-container>
        <handlers>
            <file name="welcome-content" path="${jboss.home.dir}/welcome-content"/>
        </handlers>
        <filters>
            <response-header name="server-header" header-name="Server" header-value="JBoss-EAP/7"/>
            <response-header name="x-powered-by-header" header-name="X-Powered-By" header-value="Undertow/1"/>
        </filters>
    </subsystem>

Comment: this is correct for WildFly, not for JBoss classic.
Comment: Thanks @jwenting for your feedback. I'm running jboss-eap-7 standalone mode and it works, and for domain mode I have to set max-post-size for ajp-listener. Can you enlight me please?
Comment: EAP7 is the commercial version of Wildfly :) Classic is JBoss4 (and maybe 5), which have a completely different architecture. They're also very old (think 10+ years) but still in use.
Comment: Thanks @jwenting again for this info. For this old version, we should look into the manual or the source code directly.
Comment: Which is what the other 2 answers did 10 years ago :)
Answer: Lets say we have the a default standalone configuration settings of undertow module which sets max-post-size to 10mb. Documentation on RedHat.
<subsystem xmlns="urn:jboss:domain:undertow:12.0" default-virtual-host="default-host" statistics-enabled="true">
            <buffer-cache name="default"/>
            <server name="default-server" default-host="default-host">
                <http-listener name="http" socket-binding="http" max-parameters="20000" allow-unescaped-characters-in-url="true" proxy-address-forwarding="true" enable-http2="true"/>
                <host name="default-host" alias="localhost">
                    <filter-ref name="samesite-cookie"/>
                    <filter-ref name="hsts-header"/>
                    <filter-ref name="x-frame-options"/>
                    <filter-ref name="x-xss-protection"/>
                    <filter-ref name="x-content-type-options"/>
                    <filter-ref name="gzipfilter"/>
                    <http-invoker security-realm="ApplicationRealm"/>
                </host>
            </server>
...

To change the max-post-size variable to whatever variable is desire we can connect to JBOSS CLI and execute the following command to update the configuration. If you do not know how to connect to JBOSS CLI, here is the official documentation.
/subsystem="undertow"/server="default-server"/http-listener="http":write-attribute(name=max-post-size,value=11534336)

Once the command is executed your standalone configuration should look like that:
<subsystem xmlns="urn:jboss:domain:undertow:12.0" default-virtual-host="default-host" statistics-enabled="true">
            <buffer-cache name="default"/>
            <server name="default-server" default-host="default-host">
                <http-listener name="http" socket-binding="http" max-post-size="11534336" max-parameters="20000" allow-unescaped-characters-in-url="true" proxy-address-forwarding="true" enable-http2="true"/>
                <host name="default-host" alias="localhost">
                    <filter-ref name="samesite-cookie"/>
                    <filter-ref name="hsts-header"/>
                    <filter-ref name="x-frame-options"/>
                    <filter-ref name="x-xss-protection"/>
                    <filter-ref name="x-content-type-options"/>
                    <filter-ref name="gzipfilter"/>
                    <http-invoker security-realm="ApplicationRealm"/>
                </host>
            </server>
...

This means that now the max-post-size is set to 11mb.


how to deal with absolute value/norm when computing volume

Question: Compute the 4-dimensional volume of the set $\ E\ \subset \mathbb{R}^{4}\ $ consisting of all$\ (x,y,z,t) \in \mathbb{R}^{4}\ $ such that
$$\left|x\right|+\left|x+2y\right|+\left|x+2y+3z\right|+\left|x+2y+3z+4t\right|\ \leq a\ $$
where $\ a > 0\ $ is a given number.
My question is:  can i consider the relation
$\left|x\right|+\left|x+2y\right|+\left|x+2y+3z\right|+\left|x+2y+3z+4t\right|\ \leq a\ $
to be the same as:
$\ {x}^{2}+{(x+2y)}^{2}+{(x+2y+3z)}^{2}+{(x+2y+3z+4t)}^{2} \leq a?\ $
or could it also be equivalent to:
$\ {x}+{(x+2y)}+{(x+2y+3z)}+{(x+2y+3z+4t)} \leq a?\ $
Otherwise, I am not sure how to deal with the case of absolute value or presence of norm when computing volume.
Comment: Neither of those alternatives is correct. You could figure that out by trying some examples. To think about how to attack the problem, work out a two dimensional analogue where you can draw a picture. what's the area of the figure with $|x| + |x+2y| \le  a$?
Comment: @EthanBolker, i deleted my previous my comment realizing I made a mistake.  After thinking some more, i realized isn't what you are suggesting the same as using change of variable to calculate the area of the linear transformation $T(x,y)=(x, x+2y)$?
Answer: No, it is not true.  The sum of absolute values gives you a polyhedron while the sum of squares will give you a round object.  If you work in $2D$, you find that $|x|+|y|= a$ is a square oriented on a diagonal, while $x^2+y^2= a^2$ is a circle of radius $a$.
You are expected to set up a four dimensional integral.  As all the terms are positive, the first tells you that the $x$ integral runs from $-a$ to $+a$.  Now find the range of $y$ that corresponds to a given $x$.  That will give you the range of the $y$ interval.  Keep going.
Comment: the range of y would be between $a-4x$ and $-a-4x$?
Comment: No, you have $|x+2y| \le a-|x|$ because you can always choose $z,t$ to make the last two absolute values $0$.  You will have to condition on the sign of $x$
Comment: can I somehow turn this into a question of change of variables.  I remember in vector calculus texts, there are always examples where a parallelogram/rotated square gets transformed into an unrotated square.  So can't I just use $T(x,y)=(x, x+2y)$ and compute the area by calculating the determinant for the derivative matrix of T?
Comment: Yes, that is a good approach.  I didn't think of it.  I think it will be much simpler than what I proposed.
Comment: do I still have to set up a soubkw integral where the integrand is 1 and I input the limits of integration according to the change of variable for transformation T?


Sieve of Eratosthenes for higher numbers than 2 Million [C]

Question: I am trying to make a program which names all prime numbers up to n. When I enter numbers > 2 Million, the program crashes. Can someone help me?
#include <stdio.h>
#include <math.h>

void sieve(unsigned long long int n, char primes[]);

int main()
{
  unsigned long long int i, n = 2000000; // find the primes up to 500000
  char v[n];
  sieve(n, v);
  for (i=0;i<n;i++)
    if (v[i] == 1)
      printf("%I64u\n",i); // this just prints out each value if it's Prime
}

void sieve(unsigned long long int n, char primes[])
{
  unsigned long long int i, j;
  for (i=0;i<n;i++)
    primes[i]=1; // we initialize the sieve list to all 1's (True)
  primes[0]=0,primes[1]=0; // Set the first two numbers (0 and 1) to 0 (False)
  for (i=2;i<sqrt(n);i++) // loop through all the numbers up to the sqrt(n)
    for (j=i*i;j<n;j+=i) // mark off each factor of i by setting it to 0 (False)
      primes[j] = 0;
}

Error message:

Process returned -1073741571 (0xC00000FD) execution time : 2.032 s
Comment: Using `i` as a counter for a loop *and* an nested loop? Sounds like a trouble.
Comment: Use bit storage. That will give you 8x the range.
Comment: Knowing the message with which it crashes might help. `char v[n];` for n=2M inside main may be an issue as that variable will be allocated from the stack, which in most cases is quite limited in size.
Comment: @fvu Process returned -1073741571 (0xC00000FD)   execution time : 2.032 s
Comment: @EugeneSh. No. The programm works perfectly for numbers up to 2000000. I need to use the same i in both loops
Comment: @EugeneSh. The indenting is off, but assuming the brackets are correct, the second for loop using `i` is not nested within the first for loop. The first for loop is purely for initialization of the `primes` array
Comment: @Taelsin Oh my. You are right. The indentation is not just terrible, it is highly misleading here.
Comment: `char v[n]` puts two megabytes on the stack--that might be too much for your runtime. Use `malloc`. Even better, use malloc and bit-manipulation so that you only need one bit per number.
Answer: Stick to the name of this website; you are experiencing a stack overflow. ;-)
Try
char *v = malloc(n);

and
void sieve(unsigned long long int n, char *primes)

respectively. Of course, you will also need
free(v);

Apart from that, I haven't checked your algorithm for correctness.
Comment: @chux We are talking about less than 2 MB of memory. For heap allocation, this can only become problematic for really exotic systems. And I do not assume that the OP is doing DSP programming. But ok, for use with a lot larger n, a check would be useful.
Comment: I never worked with pointers or the malloc function, but I tried to do this anyway. So now I have the following problem:
at the line with
"sieve(n, v);"
neither "sieve(n, v);" nor "sieve(n, v*);" works. What should I do there?
With v: "passing argument 2 of 'sieve' from incompatible pointer type"
With *v: "'sieve' makes pointer from integer without a cast"
Comment: Pedram Azad, As OP is having trouble which may later include memory capacity issues, checking for `malloc()` success is prudent.
Comment: It should compile without any further changes. Maybe you forgot to adapt the declaration or the definition of your function sieve? You need to adapt both.
Comment: OP could be on an interactive system emulating a real computer and for student purposes works in a small sandbox - the initial issue is a memory one.  IAC, learners do _interesting things_ and checking `malloc()` can discover an error faster.  Yet if a goal is [code golf](https://codegolf.stackexchange.com), then yes, do not bother with a `malloc()` check.
Answer: The problem is because your program did not have enough memory reserved and as mentioned by @Pedram Azad you had an stack overflow. You can by-pass that by allocating more memory to your var (malloc).
Also, you need to start using brackets for your code blocks (loops and conditional statements). It helps to visualize problems. The indentation was very confusing.
#include <stdio.h>
#include <math.h>
#include <stdlib.h>

void sieve(unsigned long long int, char *);

int main()
{
  unsigned long long int i, n = 63000000; // find the primes up to 500000
  char *v = (char*) malloc(n*sizeof(char));
  sieve(n, v);
  for (i=0; i<n; i++) {
    if (v[i] == 1) {
      printf("%lld\n",i); // this just prints out each value if it's Prime
    }
  }
  free(v);
}

void sieve(unsigned long long int n, char *primes)
{
  unsigned long long int i, j;
  for (i=0; i<n; i++) {
    primes[i]=1; // we initialize the sieve list to all 1's (True)
  }
  // Set the first two numbers (0 and 1) to 0 (False)
  primes[0]=0;
  primes[1]=0;
  // loop through all the numbers up to the sqrt(n)
  for (i=2; i<sqrt(n); i++) {
    for (j=i*i; j<n; j+=i) {
      // mark off each factor of i by setting it to 0 (False)
      primes[j] = 0;
    }
  }
}


Partition integers into $M$ sets

Question: Given a circular list of two numbers $-1,+1$.I have to partition them into $M$ sets each containing $K$ numbers. Each set has to consist of consecutive $K$ numbers from that list. The set can start from any point in the list.
1.A set is called positive if number of $+1$ are greater than $-1$.
2.A set is called negative if number of $-1$ are greater than $+1$.
Now I want to know if there's a way to partition them such that the number of positive sets are more than number of negative sets.
Take $K$ to be odd for simplicity so that a set can be either called positive or negative.
For eg- List $A$ = $(-1, -1, 1, 1, -1, 1, 1, -1, -1)$ and I have to partition it into $3$ sets with $3$ numbers in it. Then there are many ways :
1. {$A_3$,$A_4$,$A_5$}, {$A_6$,$A_7$,$A_8$} and {$A_9$,$A_1$,$A_2$}

{$A_2$,$A_3$,$A_4$}, {$A_5$,$A_6$,$A_7$} and {$A_8$,$A_9$,$A_1$}

Here $2$ positive sets and $1$ negative set. So I can partition it.
I can only think of making every possible combination. Is there a way to do it efficiently and optimally.
Comment: There are only $K$ such divisions, which is not much to check.
Comment: @SimonMarynissen How do you check it ? Can you explain it ?
Comment: Just making every possible combination, I can't think of a better way at the moment.
Comment: @SimonMarynissen This would take quadratic time. Not efficient at all.
Comment: That depends on whether $K$ is much smaller than $|M|$.
Comment: @SimonMarynissen It is not necessary.
Answer: Let $N=KM$. Let $S_i = A_i+\ldots +A_{i+K-1}$, $A_{N+i}=A_{i}$. Obviously, $\{A_i,\ldots ,A_{i+K-1}\}$ is positive if $S_i$ is positive, and $\{A_i,\ldots ,A_{i+K-1}\}$ is negative if $S_i$ is negative.
The $S_i$ can be calculated recursively with little effort:
$$
S_{i+1} = S_i+A_{i+K}-A_{i}
$$
For each $j\in \{0,\ldots ,K-1\}$, introduce a counter $p_j$ ("positive") and an counter $n_j$ ("negative").
Start with initializing your counters and calculating $S_1$. Then calculate each $S_i, \; i=1,\ldots, N$ with the recursive formula shown above. If $S_i >0$, increase the $p_j$ for which $j\equiv i\pmod{K}$. If $S_i<0$, increase the $n_j$ for which $j\equiv i\pmod{K}$. At the end, find an index $j$ for which $p_j$ is greater than $n_j$. This $j$ gives you the starting position in the list. Use the biggest $p_j$ if you want to have the optimum.
If we apply this method to the given example, we get (one after another)
$$
(S)_{i\in\{1,\ldots,9\}} = (-1,\,1,\,1,\,1,\,1,\,1,\,-1,\,-3,\,-3)
$$
For the counters $p_0$ and $n_0$, we have taken the elements $S_3$, $S_6$ and $S_9$ into account (while we calculated the $S_i$). We find that two of them are positive and one is negative, therefore $p_0=2$ and $n_0=1$ in the end.
For the counters $p_1$ and $n_1$, we have taken the elements $S_1$, $S_4$ and $S_7$ into account. We find that one of them is positive and two are negative, therefore $p_1 = 1$ and $n_1=2$.
For the counters $p_2$ and $n_2$, we have taken the elements $S_2$, $S_5$ and $S_8$ into account. We find that two of them are positive and one is negative, therefore $p_2=2$ and $n_2=1$.
For $j=0$ and $j=2$, $p_j>n_j$ holds. Therefore we can split the list either in front of the elements with indices $\equiv 0\pmod{3}$ or in front of the elements with indices $\equiv 2\pmod{3}$.
Comment: Can you explain it briefly with the given example? The explanation is little hard to follow. Also if $K,M$ both are odd, is there any more optimization possible ?
Comment: Is that $A_{N+i}$ in the $S_i$ a typo ?
Comment: Where is a $A_{N+i}$ in the $S_i$?
Comment: The definition $A_{N+i} = A_i$ is used to avoid distinction of cases. We extend the series of $A$s in order to make the description easier. The list is circular
Comment: Sorry, I got it now. Can you explain with example in the question or any small example,please ? It would be very helpful. It's a little difficult for me to understand the solution as of right now.
Comment: Thanks but now I am not getting only this part :After finding $p_j,n_j$ for all value of $j$'s ,how do I determine if the solution exists. Do I check for every  $j$, $p_j>n_j$ ?
Comment: Depending on whether you want to have one solution or if you want to have the optimal solution (whatever that means), you have to look for the first occurrence of $p_j>n_j$ and then stop, or you have to check for every $j$.

Partition integers into $M$ sets


Set useState hook in a async loop

Question: I'm new about reactJs.
I'm trying to concatenate results in async loop, but something is wrong.
setState not save correctly, when I print it I can see it's an empty array, I think because there is inside an async call.
How I can solve that? Please suggest me.
function App() {

  const [data, setData] = useState({data:[]});

  const handleChildSubmit = (data) => {
    setData(data);
  }

  return (

      <Form onChildSubmit={handleChildSubmit} />
      <Results flights={data} />

  );
}

const Form = ( {onChildSubmit} ) => {

    const [dati, setDati] = useState([]);

    const onFormSubmit = async (e) => {
        e.preventDefault();

        // Flights search Parameters
        const data = new FormData(e.target);
        const dateFrom = data.get('dateFrom');
        const dateTo = data.get('dateTo');
        const departureDay = data.get('day');
        const placeFrom = data.get('placeFrom');
        const placeTo = data.get('placeTo');
        let dayDeparture;
        const daysDeparture = getDayOfWeekArray(dateFrom,dateTo,departureDay);

        // Loop of Fly Search in range time
        for(let i=0; i < daysDeparture.length; i++){
            dayDeparture = daysDeparture[i];
            axios.get('https://api.skypicker.com/flights?flyFrom='+placeFrom+'&to='+placeTo+'&dateFrom='+dayDeparture+'&dateTo='+dayDeparture+'&partner=picky')
            .then(res => {

                setDati([...dati, res.data]);
                onChildSubmit(dati);

            })
            .catch(function (error) {
                console.log('error: '+error);
            })
            .finally(function () {
            });
        }

    }

Comment: on an unrelated note, your `async` function has no `await` expression. You resolve your Promise with `then()` instead.
Answer: The problem is that useState here gives you the dati variable with a specific value. Then your asynchronous stuff happens, and setDati() is called multiple times, but dati is does not change until the form is re-rendered and you then call onFormSubmit again.
You have a few options.
You could add the results only once as an array.
const results = []

for(let i=0; i < daysDeparture.length; i++){
    dayDeparture = daysDeparture[i];
    const res = await axios.get('https://api.skypicker.com/flights?flyFrom='+placeFrom+'&to='+placeTo+'&dateFrom='+dayDeparture+'&dateTo='+dayDeparture+'&partner=picky');
    results.push(res.data);
}

// Add all results when all are fetched.
setDati([...dati, ...results])

Or useReducer which reliably gives you the latest version of the state, right at the time that you change it, so you don't have stale data.
// Something like...

function reducer(state, action) {
  switch(action.type) {
    case 'append':
      return [...state, action.payload]
  }
}

function YourComponent() {
  const [dati, dispatch] = useReducer(reducer, [])

  const onFormSubmit = async (e) => {
    for(let i=0; i < daysDeparture.length; i++){
        dayDeparture = daysDeparture[i];
        const res = await axios.get('https://api.skypicker.com/flights?flyFrom='+placeFrom+'&to='+placeTo+'&dateFrom='+dayDeparture+'&dateTo='+dayDeparture+'&partner=picky')
        dispatch({type: 'append', payload: res.data})
    }
  }
}

Answer: useState provides a way to use the previous state when updating (just like the callback way when you are using a class component), could give that a shot
        .then(res => {
            setDati(prevDati => ([...prevDati, res.data]));
            onChildSubmit(dati);

        })

Set useState hook in a async loop


Does non-response bias affect the validity of a statistical model?

Question: I want to build a (generalised linear mixed) model on some survey data. The PROC GENMOD command in SAS doesn't admit weighting in the sense of survey weights. I am not interested in population-level frequencies, but do want to draw valid conclusions about how covariates interact with each other and the dependent variable in the real world. Does the lack of weights matter?
Comment: What is a "valid" conclusion about the "real world" if not an inference about the population?
Comment: An opportunity to sound clever?
Comment: I don't follow.  I'm not trying to be snarky. I just think you're in fact doing what you say you aren't doing.
Comment: I agree that conclusions about the real world are inferences about the population. What I'm saying above is that I am not interested in population-level frequencies, but in how different characteristics are related to each other. I am using the ending "in the real world" to emphasise that I am asking whether the conclusions from unweighted data will be applicable outside the sample. I'm now pretty sure they won't, though. I'm not necessarily keen on exploring the semantic further, but I'm grateful that you have engaged with my question.
Answer: If you are interested in making inferences on a group larger than your sample, I suspect that the answer is "yes," but how much bias is introduced?
The typical argument is that those who do not answer the survey are categorically different than those who do. Chapter 6 of the textbook Survey Methodology by Groves et al and related papers, partition non-response into three groups:

refusal
non-contact or miss (never available)
inability to respond (eg, language barrier)

If a cause behind one or more of these non-response categories is correlated with your outcome of interest, then there is a danger that your estimates  will be biased.
In some instances, you may be able to control for the non-response causes through modeling or weighting. When this is not a possibility, AAPOR recommends that, as a minimum, you report the response rate (various formulas might be found on their website).
The textbook chapter mentioned above as well as other research papers on this topic have found that well thought out and executed surveys can produce unbiased results even with a fairly high response rate, but these are typically surveys conducted with the great care.
My recommendation is to report the response rate (or a couple response rates based on different formulas) and discuss how this might affect your estimates based on the literature.
Comment: I appreciate your thoughts. I can easily think of scenarios where unweighted analysis would create problems in drawing general conclusions. Let's say blue-collar workers were prevalent in a particular part of the country, and also took more time to get re-employed. If I had fewer blue-collar workers than is typical, since they may feel they have better things to do than answer a survey, then my analysis of propensity of re-employment of blue-collar workers would not be problematic per se. However, the part of the country they are from would over-predict reemployment.
Comment: This is a good response, but seems more relevant to the generalization of means, proportions, etc. to the larger population. With respect to non-response bias in a model, there will only be bias if non-response is correlated with *both* the outcome and predictor. Am I wrong? In practice, survey weights are rarely included in regression models, though I know there is some debate about this. But say women are under-represented and so we post-stratify for calculation of means, etc., that makes sense, but if we include gender as a covariate in our model with no weights, then where is the bias?