c++11 – Error Id returned 1exit status |Dev c++

Eu estou a tentar criar um jogo mas sou iniciante.
Eu escrevi o código e esta me a dar ‘(Error) Id returned 1exit status’
Alguém pode me ajudar?
Codigo:

#include <iostream>

#include <GL/glut.h>
using namespace std;

void theCube(){
glColor3f(1,1,1);
glutSolidCube(0.4);
}

void init(){
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluPerspective(35,1.0f,0.1f,1000);
glMatrixMode(GL_MODELVIEW);
glEnable(GL_DEPTH_TEST);
glClearColor(0.1,0.1,0.1,1);
}

void display(){
glRotatef(40,1,1,0);
theCube();
glutSwapBuffers();
}

int main(int argc, char **argv){
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_DOUBLE);
glutInitWindowSize(800,600);
glutCreateWindow(“”);
glutDisplayFunc(display);
glutMainLoop();
init();
return 1;
}

design – Use the type returned by a function as information

Over time I become used to use the type of the returned value of a function as a piece of additional information.

For example:
A function that is supposed to return or an array if the arguments are correct and can find a result, can pass a specific enum when arguments are incorrect or the expected result cannot be found.
Then I can test the type to sort the behaviour of the receiving code.

I can’t always use a typed function in the same way because the value that I reserve to explain what’s wrong removes a possible valid result.

I can see some other benefits and the main is that testing the type of the returned value is a very separated operation from the normal flow of the code and it seems more methodical to me.
Also, the segmentation now possible increases the flexibility of the code.
So, I’m quite sure that I write less code and, once one gets used, the code is readable.

  1. Is it acceptable?
  2. I’m going to work with an agency on some projects, can I ask if I can use this approach or is it against the best practices?

apt – E: Sub-process /usr/bin/dpkg returned an error code (1) DPKG ERROR

I’m having this error when doing $ sudo apt upgrade :

Error 24 : Write error : cannot write compressed block

E: mkinitramfs failure cpio 141 lz4 -9 -l 24

update-initramfs: failed for /boot/initrd.img-5.4.0-7634-generic with 1.

dpkg: error processing package linux-firmware (–configure):

installed linux-firmware package post-installation script subprocess returned error exit status 1

Errors were encountered while processing:

linux-firmware

E: Sub-process /usr/bin/dpkg returned an error code (1)

I tried the following:

$ sudo apt-get clean

$ sudo apt-get upgrade

$ sudo apt-get install -f

$ sudo apt-get dist-upgrade

I also tried $ flatpak update

What could be the solution?

python – Error: Command ‘[‘/path/to/env/bin/python3.7’, ‘-Im’, ‘ensurepip’, ‘–upgrade’, ‘–default-pip’]’ returned non-zero exit status 1

I just installed python3.7 on my 18.04LTS via the deadsnakes ppa:

sudo add-apt-repository ppa:deadsnakes/ppa
sudo apt install python3.7 -y

Now I want to create a virtual environment with python3.7 -m venv env but I get

Error: Command '['/path/to/desired/env/bin/python3.7', '-Im', 'ensurepip', '--upgrade', '--default-pip']' returned non-zero exit status 1.

python3 -m venv env0 worked fine before.

Why does this happen?
What can I do to create a virtual environment for python3.7 on Ubuntu 18.04LTS?

magento2 – Magento 2 how to add a field to a model that is natively returned in a collection (Bundle Option)

How do I add a new field to a Model that is natively retrieved when a collection is called on the Model? I would like to do it on Bundle Option – but also understand generically how to do this.

There are lots of questions/answers showing how to inject a field into a view, but this is only a small part of the total task. For example, I have a bundle product that has option groups, and then products within the groups. I want to add a text field to the option group that can be edited, saved in the admin, and also shown on the front end.

In order to add the field to the view in admin panel, I would create a plugin or preference to the Ui/DataProvider/Product/Form/Modifier/BundlePanel class. Doing this would only display the field and store it in the database assuming the field exists.

Next,
If I want to read the values from the database to show what saved in the admin, I could modify/override the modifyData method
“MagentoBundleUiDataProviderProductFormModifierComposite”. But this only will retrieve my custom field when viewed in the admin, nowhere else. It also requires loading or doing some extra database operation.

Next,
If I want to show the same value in the front end in a template by just using magic methods such as getTitle or getRequired, it doesn’t work. This is because the field is not apart of the default collection, and the previous method to retrieve the field only works in the context of admin.

I would prefer to add the field to the collection itself so anywhere I would access the options from a bundle, it would automatically be retrieved. IMO, it would be a much better solution to add the field to the collection then have to write multiple modifications to get it’s value depending on where I am in the system. I also didn’t see how to load a bundle product option directly. All answers I found are loading the bundle product, then iterating over it’s options – which is expensive.

bitcoind – cpuminer: Running two nodes -The requested URL returned error: 500 Internal Server Error, json_rpc_call failed, retry after 30 seconds

I’m trying to mine new blocks using cpuminer. My blockchain network runs on localhost on the testnet network with two nodes. When I’m trying to mine the blocks I’m receiving the following error:

* TCP_NODELAY set
(2020-08-19 10:46:01) Binding thread 6 to cpu 6
(2020-08-19 10:46:01) Binding thread 4 to cpu 4
* Connected to 127.0.0.1 (127.0.0.1) port 18001 (#0)
* Server auth using Basic with user 'liork'
(2020-08-19 10:46:01) Binding thread 2 to cpu 2
> POST / HTTP/1.1
Host: 127.0.0.1:18001
Authorization: Basic bGlvcms6aXJvY2s=
Accept-Encoding: deflate, gzip, br
Content-Type: application/json
User-Agent: cpuminer/2.5.1
X-Mining-Extensions: midstate
Content-Length: 147

* upload completely sent off: 147 out of 147 bytes
(2020-08-19 10:46:01) Binding thread 0 to cpu 0
* Mark bundle as not supporting multiuse
* The requested URL returned error: 500 Internal Server Error
* Closing connection 0
(2020-08-19 10:46:01) HTTP request failed: The requested URL returned error: 500 Internal Server Error
(2020-08-19 10:46:01) json_rpc_call failed, retry after 30 seconds

My nodes configuration:

Node1:

...
# Options only for testnet
(test)
connect=127.0.0.1:17002
rpcport=18001
listen=1
port=17001
rpcuser=myuser
rpcpassword=mypassword
...

Node2:

...
# Options only for testnet
(test)
connect=127.0.0.1:17001
rpcport=18002
listen=1
port=17002
rpcuser=myuser
rpcpassword=mypassword
...

I’m running the cpuminer using the command: ./minerd --url=http://127.0.0.1:18001 --user=myuser --pass=mypassword --coinbase-addr=my_address --protocol-dump

numerical integration – Integrate over one variable of a 2D interpolating function returned from NDEigensystem

I’m trying to implement the answer for “Integrate only one variable of a 2D interpolating function” (https://mathematica.stackexchange.com/a/161962/73672) but for interpolating functions returned from NDEigenSystem it isn’t working.

First I solved for my required eigenfunctions and stored them as “funs”:

ClearAll("Global`*");
ClearAll(vals, funs, schröd);
A = 0.025;
Subscript(V, 0) = 1;
d = 2;
schröd = -A*d^2 (Pi)*D((Psi)(n, (CurlyPhi)), {(CurlyPhi), 2}) + 
   A/(4 (Pi)) ((CurlyPhi)*(CurlyPhi)*(Psi)(n, (CurlyPhi)) + 
      2 I*D((Psi)(n, (CurlyPhi)), {n, 1}) - 
      D((Psi)(n, (CurlyPhi)), {n, 2})) - 
   Subscript(V, 
     0) ((Cos(2 (Pi)*d*n)) + Cos((CurlyPhi)) - 20) (Psi)(
     n, (CurlyPhi));
Subscript(n, min) = -1/2; Subscript(n, max) = 1/2; 
Subscript((CurlyPhi), min) = -(Pi); 
Subscript((CurlyPhi), max) = (Pi);
(CapitalOmega) = 
  Rectangle({Subscript(n, min), 
    Subscript((CurlyPhi), min)}, {Subscript(n, max), 
    Subscript((CurlyPhi), max)});

{vals, funs} = 
  NDEigensystem({schröd, 
    PeriodicBoundaryCondition((Psi)(n, (CurlyPhi)), 
     Subscript((CurlyPhi), min) <= (CurlyPhi) <= 
       Subscript((CurlyPhi), max) && n == Subscript(n, max), 
     FindGeometricTransform({{Subscript(n, min), 
         Subscript((CurlyPhi), min)}, {Subscript(n, min), 
         Subscript((CurlyPhi), max)}}, {{Subscript(n, max), 
         Subscript((CurlyPhi), min)}, {Subscript(n, max), 
         Subscript((CurlyPhi), max)}})((2))), 
    PeriodicBoundaryCondition(Exp(I 2 (Pi) n)*(Psi)(n, (CurlyPhi)),
      Subscript(n, min) <= n <= Subscript(n, max) && (CurlyPhi) == 
       Subscript((CurlyPhi), max), 
     FindGeometricTransform({{Subscript(n, min), 
         Subscript((CurlyPhi), min)}, {Subscript(n, max), 
         Subscript((CurlyPhi), min)}}, {{Subscript(n, min), 
         Subscript((CurlyPhi), max)}, {Subscript(n, max), 
         Subscript((CurlyPhi), 
          max)}})((2)))}, (Psi), {n, (CurlyPhi)} (Element) 
    Rectangle({Subscript(n, min), 
      Subscript((CurlyPhi), min)}, {Subscript(n, max), 
      Subscript((CurlyPhi), max)}), 2);
Plot3D({Evaluate(Abs({funs((1))(n, (CurlyPhi))  }^2))}, {n, 
  Subscript(n, min), Subscript(n, max)}, {(CurlyPhi), 
  Subscript((CurlyPhi), min), Subscript((CurlyPhi), max)}, 
 PlotRange -> All, 
 PlotLabel -> 
  "Eig  fun    1 ", AxesLabel -> Automatic)

The answer to the other question was as follows:

da = 
  Flatten(
    Table(
      {t, tau, N @ Sin(2 (t + 3 tau)) Exp(-2 t - tau)}, 
      {t, 0, 2, 2/100}, {tau, 0, 5, 5/100}),
    1);
f = Interpolation @ da;
{{x1, x2}, {y1, y2}} = f("Domain");
intx = Integrate(f(x, y), x) /. x -> x2;
    
nintx(y_?NumericQ) := Module({x}, NIntegrate(f(x, y), {x, x1, x2}));
    
Plot(nintx(y), {y, y1, y2}, PlotRange -> All)

However, trying to implement this myself gives an error after the third line, I believe because it reads n2 as 0.5:

f = funs((1));
{{n1, n2}, {φ1, φ2}} = f("Domain");
intn = Integrate(f(n, φ), n) /. n -> n2;

General::ivar: 0.5 is not a valid variable.
Integrate::ilim: Invalid integration variable or limit(s) in 0.5.

list manipulation – Asking for the value returned by Solve

The command Solve gives a list of Rule objects. Rule Objects have the property of replace a symbol by a value. For example,

Solve((r-2)(r-4)(r-3)==0,r)

gives the output

{{r -> 2}, {r -> 3}, {r -> 4}}

Each sublist in the list contains a Rule object. To Make the the replacement you have to use the ReplaceAll buit-in function :

ReplaceAll(r, Solve((r - 2)(r - 3)(r - 4)==0,r))
{2,3,4}

or its shorthand form

r/.Solve((r - 2)(r -3)(r - 4)==0, r)
{2,3,4}

And so you can extract the desired solution.

plotting – Integrate over one variable of a 2D interpolating function returned from NDEigensystem

I’m brand new to mathematica and have some 2D eigenfunctions, $psi(n,varphi)$, returned from NDEigensystem. The continuous variable $varphi$ can be represented as $varphi=2pi(varphi)+bar varphi$ where $(varphi)inmathbb{Z}$ and $bar varphiin(-pi,pi )$.

I need to plot $$ psi(varphi)=int_{-1/2}^{1/2}dn e^{-in(varphi)} psi(n,bar varphi). $$ I have managed to get some plots, but as they are not what I expected and as most of my code is adapted from varying answers on stackexchange, I do not think I have done it correctly.

First I solved for the eigenfunctions and stored them as “funs”:

    A = 0.05; Subscript(V, 0) = 1 ; d = 2; schröd = -A*d^2 (Pi)*D((Psi)(n, (CurlyPhi)), {(CurlyPhi), 2}) +     A/(4 (Pi)) ((CurlyPhi)*(CurlyPhi)*(Psi)(n, (CurlyPhi)) + 
      2 I*D((Psi)(n, (CurlyPhi)), {n, 1}) - 
      D((Psi)(n, (CurlyPhi)), {n, 2})) -     Subscript(V, 
    0) ((Cos(2 (Pi)*d*n)) + Cos((CurlyPhi))) (Psi)(n, (CurlyPhi)); Subscript(n, min) = -1/2; Subscript(n, max) = 1/2; Subscript( (CurlyPhi), min) = -(Pi); Subscript((CurlyPhi), max) = (Pi); 

{vals, funs} = NDEigensystem({schröd,
    PeriodicBoundaryCondition((Psi)(n, (CurlyPhi)), 
     Subscript((CurlyPhi), min) <= (CurlyPhi) <= 
       Subscript((CurlyPhi), max) && n == Subscript(n, max) , 
     FindGeometricTransform({{Subscript(n, min), 
         Subscript((CurlyPhi), min)}, {Subscript(n, min), 
         Subscript((CurlyPhi), max)}}, {{Subscript(n, max), 
         Subscript((CurlyPhi), min)}, {Subscript(n, max), 
         Subscript((CurlyPhi), max)}})((2))), 
    PeriodicBoundaryCondition(Exp(I 2 (Pi) n)*(Psi)(n, (CurlyPhi)),
      Subscript(n, min) <= n <= Subscript(n, max) && (CurlyPhi) == 
       Subscript((CurlyPhi), max), 
     FindGeometricTransform({{Subscript(n, min), 
         Subscript((CurlyPhi), min)}, {Subscript(n, max), 
         Subscript((CurlyPhi), min)}}, {{Subscript(n, min), 
         Subscript((CurlyPhi), max)}, {Subscript(n, max), 
         Subscript((CurlyPhi), max)}})((2)))}, (Psi)(
    n, (CurlyPhi))   , {n, (CurlyPhi)} (Element) 
    Rectangle({Subscript(n, min), Subscript((CurlyPhi), 
      min)}, {Subscript(n, max), Subscript((CurlyPhi), max)}), 8);

Then I created “MyRound” to be able to evaluate $(varphi)$ (labelled K in my code) given any $varphi$:

    SetAttributes(RoundPos, Listable)
        RoundPos(n_) :=
          If(FractionalPart(n) >= 1/2, Ceiling(n), Floor(n));
        SetAttributes(RoundNeg, Listable)
        RoundNeg(n_) := If(FractionalPart(n) < -1/2, Floor(n), Ceiling(n));
        SetAttributes(MyRound, Listable)
        MyRound(n_) := If(n >= 0, RoundPos(n), RoundNeg(n));
        K((CurlyPhi)_) := MyRound((CurlyPhi)/(2 (Pi)))

And finally I tried to calculate the required integral and plot the results:

    Subscript((CurlyPhi), subdivisions) = 0.1 ;
    Needs("FunctionApproximations`")
    
    Table(f = Exp(I*n*K((CurlyPhi)))*funs((i)); 
      t = Abs(
       Table(NIntegrateInterpolatingFunction(
         f, {n, -0.5, 0.5}), {(CurlyPhi), -(Pi), (Pi), 
         Subscript((CurlyPhi), subdivisions)})^2);
     u = Range(-(Pi), (Pi), Subscript((CurlyPhi), subdivisions));
     data = Transpose@{u, t};
     ListPlot(data, ImageSize -> 250), {i, 2}) 

I would also like to plot these $psi(varphi)$ for a domain larger than $varphiin(-pi,pi )$ but I do not know how to make the eigenfunction calculate $barvarphi$ given $varphi$ in the NIntegrateInterpolatingFunction command, or in general. Ideally I would make my function $psi(n,varphi)$ accept values of $varphi$ but evaluate $barvarphi$.

Another method I tried to implement the integral with used this stackexchange answer (using the questioner’s interpolating function):

    da = Flatten(
       Table({t, tau, N@Sin(2 (t + 3 tau)) Exp(-2 t - tau)}, {t, 0, 2, 
         2/100}, {tau, 0, 5, 5/100}), 1);
    f = Interpolation@da;
    {{x1, x2}, {y1, y2}} = f("Domain");
    intx = Integrate(f(x, y), x) /. x -> x2;
    
    nintx(y_?NumericQ) := Module({x}, NIntegrate(f(x, y), {x, x1, x2}));
    
    Plot(nintx(y), {y, y1, y2}, PlotRange -> All)

However, trying to implement this myself gives an error after the third line because it reads n2 as 0.5:


    f = funs((1));
        {{n1, n2}, {(CurlyPhi)1, (CurlyPhi)2}} = f("Domain");
        
        intn = Integrate(f(n, (CurlyPhi)), n) /. n -> n2;

General::ivar: 0.5 is not a valid variable.

Integrate::ilim: Invalid integration variable or limit(s) in 0.5.

Thank you so much in advance for your help!