Wednesday, May 1, 2019

javascript - Css transition not working on parent when showing child content



Something here...

Something here...

Something here...





When I change display:none to display:block the content is shown but the transition is not fired. I already tried changing the transition from height to all, but nothing changes. Am I doing it correctly?

javascript - remove object from js array knowing it's Id




I have array of object inside razor view (javascript code).



var myArr;


on page load contains let's say 10 objects.



one object has following structure




 - Id  
- Name


how can I remove object from js array knowing it's Id?


Answer



Try like this



var id = 2;
var list = [{

Id: 1,
Name: 'a'
}, {
Id: 2,
Name: 'b'
}, {
Id: 3,
Name: 'c'
}];
var index = list.map(x => {

return x.Id;
}).indexOf(id);

list.splice(index, 1);
console.log(list);


JSFIDDLE



Or you can utilize .filter()




Like this



var id = 2;
var list = [{
Id: 1,
Name: 'a'
}, {
Id: 2,
Name: 'b'

}, {
Id: 3,
Name: 'c'
}];
var lists = list.filter(x => {
return x.Id != id;
})
console.log(lists);



DEMO


c++ - Installation of all OpenGL libraries for development in Ubuntu 11.10



I've got a just installed ubuntu 11.10.



I follow the first answer in this question. I installed:
freeglut3
freeglut3-dev



igor@ubuntu:~$ sudo apt-get install freeglut3
[sudo] password for igor:

Reading package lists... Done
Building dependency tree
Reading state information... Done
The following NEW packages will be installed:
freeglut3
0 upgraded, 1 newly installed, 0 to remove and 253 not upgraded.
Need to get 77.5 kB of archives.
After this operation, 315 kB of additional disk space will be used.
Get:1 http://us.archive.ubuntu.com/ubuntu/ oneiric/main freeglut3 i386 2.6.0-1ubuntu2 [77.5 kB]
Fetched 77.5 kB in 0s (82.9 kB/s)

Selecting previously deselected package freeglut3.
(Reading database ... 125550 files and directories currently installed.)
Unpacking freeglut3 (from .../freeglut3_2.6.0-1ubuntu2_i386.deb) ...
Setting up freeglut3 (2.6.0-1ubuntu2) ...
Processing triggers for libc-bin ...
ldconfig deferred processing now taking place
igor@ubuntu:~$ sudo apt-get install freeglut3-dev
Reading package lists... Done
Building dependency tree
Reading state information... Done

The following extra packages will be installed:
libdrm-dev libgl1-mesa-dev libglu1-mesa-dev libice-dev libkms1
libpthread-stubs0 libpthread-stubs0-dev libsm-dev libx11-dev libxau-dev
libxcb1-dev libxdmcp-dev libxext-dev libxt-dev mesa-common-dev
x11proto-core-dev x11proto-input-dev x11proto-kb-dev x11proto-xext-dev
xorg-sgml-doctools xtrans-dev
The following NEW packages will be installed:
freeglut3-dev libdrm-dev libgl1-mesa-dev libglu1-mesa-dev libice-dev libkms1
libpthread-stubs0 libpthread-stubs0-dev libsm-dev libx11-dev libxau-dev
libxcb1-dev libxdmcp-dev libxext-dev libxt-dev mesa-common-dev

x11proto-core-dev x11proto-input-dev x11proto-kb-dev x11proto-xext-dev
xorg-sgml-doctools xtrans-dev
0 upgraded, 22 newly installed, 0 to remove and 253 not upgraded.
Need to get 5,673 kB of archives.
After this operation, 23.7 MB of additional disk space will be used.
Do you want to continue [Y/n]? Y
Get:1 http://us.archive.ubuntu.com/ubuntu/ oneiric/main libkms1 i386 2.4.26-1ubuntu1 [9,654 B]
Get:2 http://us.archive.ubuntu.com/ubuntu/ oneiric/main xorg-sgml-doctools i386 1:1.8-2 [10.9 kB]
Get:3 http://us.archive.ubuntu.com/ubuntu/ oneiric/main x11proto-core-dev i386 7.0.22-1 [299 kB]
Get:4 http://us.archive.ubuntu.com/ubuntu/ oneiric/main libxau-dev i386 1:1.0.6-3 [10.2 kB]

Get:5 http://us.archive.ubuntu.com/ubuntu/ oneiric/main libxdmcp-dev i386 1:1.1.0-3 [43.9 kB]
Get:6 http://us.archive.ubuntu.com/ubuntu/ oneiric/main x11proto-input-dev i386 2.0.2-2ubuntu1 [69.0 kB]
Get:7 http://us.archive.ubuntu.com/ubuntu/ oneiric/main x11proto-kb-dev i386 1.0.5-2 [27.6 kB]
Get:8 http://us.archive.ubuntu.com/ubuntu/ oneiric/main xtrans-dev i386 1.2.6-2 [82.9 kB]
Get:9 http://us.archive.ubuntu.com/ubuntu/ oneiric/main libpthread-stubs0 i386 0.3-2.1 [3,270 B]
Get:10 http://us.archive.ubuntu.com/ubuntu/ oneiric/main libpthread-stubs0-dev i386 0.3-2.1 [2,490 B]
Get:11 http://us.archive.ubuntu.com/ubuntu/ oneiric/main libxcb1-dev i386 1.7-3 [77.9 kB]
Get:12 http://us.archive.ubuntu.com/ubuntu/ oneiric/main libx11-dev i386 2:1.4.4-2ubuntu1 [3,252 kB]
Get:13 http://us.archive.ubuntu.com/ubuntu/ oneiric/main libdrm-dev i386 2.4.26-1ubuntu1 [123 kB]
Get:14 http://us.archive.ubuntu.com/ubuntu/ oneiric/main mesa-common-dev i386 7.11-0ubuntu3 [236 kB]

Get:15 http://us.archive.ubuntu.com/ubuntu/ oneiric/main x11proto-xext-dev i386 7.2.0-3 [253 kB]
Get:16 http://us.archive.ubuntu.com/ubuntu/ oneiric/main libxext-dev i386 2:1.3.0-3 [141 kB]
Get:17 http://us.archive.ubuntu.com/ubuntu/ oneiric/main libgl1-mesa-dev i386 7.11-0ubuntu3 [9,248 B]
Get:18 http://us.archive.ubuntu.com/ubuntu/ oneiric/main libglu1-mesa-dev i386 7.11-0ubuntu3 [189 kB]
Get:19 http://us.archive.ubuntu.com/ubuntu/ oneiric/main libice-dev i386 2:1.0.7-2 [128 kB]
Get:20 http://us.archive.ubuntu.com/ubuntu/ oneiric/main libsm-dev i386 2:1.2.0-2 [86.4 kB]
Get:21 http://us.archive.ubuntu.com/ubuntu/ oneiric/main libxt-dev i386 1:1.1.1-2 [472 kB]
Get:22 http://us.archive.ubuntu.com/ubuntu/ oneiric/main freeglut3-dev i386 2.6.0-1ubuntu2 [146 kB]
Fetched 5,673 kB in 16s (336 kB/s)
Selecting previously deselected package libkms1.

(Reading database ... 125555 files and directories currently installed.)
Unpacking libkms1 (from .../libkms1_2.4.26-1ubuntu1_i386.deb) ...
Selecting previously deselected package xorg-sgml-doctools.
Unpacking xorg-sgml-doctools (from .../xorg-sgml-doctools_1%3a1.8-2_i386.deb) ...
Selecting previously deselected package x11proto-core-dev.
Unpacking x11proto-core-dev (from .../x11proto-core-dev_7.0.22-1_i386.deb) ...
Selecting previously deselected package libxau-dev.
Unpacking libxau-dev (from .../libxau-dev_1%3a1.0.6-3_i386.deb) ...
Selecting previously deselected package libxdmcp-dev.
Unpacking libxdmcp-dev (from .../libxdmcp-dev_1%3a1.1.0-3_i386.deb) ...

Selecting previously deselected package x11proto-input-dev.
Unpacking x11proto-input-dev (from .../x11proto-input-dev_2.0.2-2ubuntu1_i386.deb) ...
Selecting previously deselected package x11proto-kb-dev.
Unpacking x11proto-kb-dev (from .../x11proto-kb-dev_1.0.5-2_i386.deb) ...
Selecting previously deselected package xtrans-dev.
Unpacking xtrans-dev (from .../xtrans-dev_1.2.6-2_i386.deb) ...
Selecting previously deselected package libpthread-stubs0.
Unpacking libpthread-stubs0 (from .../libpthread-stubs0_0.3-2.1_i386.deb) ...
Selecting previously deselected package libpthread-stubs0-dev.
Unpacking libpthread-stubs0-dev (from .../libpthread-stubs0-dev_0.3-2.1_i386.deb) ...

Selecting previously deselected package libxcb1-dev.
Unpacking libxcb1-dev (from .../libxcb1-dev_1.7-3_i386.deb) ...
Selecting previously deselected package libx11-dev.
Unpacking libx11-dev (from .../libx11-dev_2%3a1.4.4-2ubuntu1_i386.deb) ...
Selecting previously deselected package libdrm-dev.
Unpacking libdrm-dev (from .../libdrm-dev_2.4.26-1ubuntu1_i386.deb) ...
Selecting previously deselected package mesa-common-dev.
Unpacking mesa-common-dev (from .../mesa-common-dev_7.11-0ubuntu3_i386.deb) ...
Selecting previously deselected package x11proto-xext-dev.
Unpacking x11proto-xext-dev (from .../x11proto-xext-dev_7.2.0-3_i386.deb) ...

Selecting previously deselected package libxext-dev.
Unpacking libxext-dev (from .../libxext-dev_2%3a1.3.0-3_i386.deb) ...
Selecting previously deselected package libgl1-mesa-dev.
Unpacking libgl1-mesa-dev (from .../libgl1-mesa-dev_7.11-0ubuntu3_i386.deb) ...
Selecting previously deselected package libglu1-mesa-dev.
Unpacking libglu1-mesa-dev (from .../libglu1-mesa-dev_7.11-0ubuntu3_i386.deb) ...
Selecting previously deselected package libice-dev.
Unpacking libice-dev (from .../libice-dev_2%3a1.0.7-2_i386.deb) ...
Selecting previously deselected package libsm-dev.
Unpacking libsm-dev (from .../libsm-dev_2%3a1.2.0-2_i386.deb) ...

Selecting previously deselected package libxt-dev.
Unpacking libxt-dev (from .../libxt-dev_1%3a1.1.1-2_i386.deb) ...
Selecting previously deselected package freeglut3-dev.
Unpacking freeglut3-dev (from .../freeglut3-dev_2.6.0-1ubuntu2_i386.deb) ...
Processing triggers for man-db ...
Setting up libkms1 (2.4.26-1ubuntu1) ...
Setting up xorg-sgml-doctools (1:1.8-2) ...
Setting up x11proto-core-dev (7.0.22-1) ...
Setting up libxau-dev (1:1.0.6-3) ...
Setting up libxdmcp-dev (1:1.1.0-3) ...

Setting up x11proto-input-dev (2.0.2-2ubuntu1) ...
Setting up x11proto-kb-dev (1.0.5-2) ...
Setting up xtrans-dev (1.2.6-2) ...
Setting up libpthread-stubs0 (0.3-2.1) ...
Setting up libpthread-stubs0-dev (0.3-2.1) ...
Setting up libxcb1-dev (1.7-3) ...
Setting up libx11-dev (2:1.4.4-2ubuntu1) ...
Setting up libdrm-dev (2.4.26-1ubuntu1) ...
Setting up mesa-common-dev (7.11-0ubuntu3) ...
Setting up x11proto-xext-dev (7.2.0-3) ...

Setting up libxext-dev (2:1.3.0-3) ...
Setting up libgl1-mesa-dev (7.11-0ubuntu3) ...
Setting up libglu1-mesa-dev (7.11-0ubuntu3) ...
Setting up libice-dev (2:1.0.7-2) ...
Setting up libsm-dev (2:1.2.0-2) ...
Setting up libxt-dev (1:1.1.1-2) ...
Setting up freeglut3-dev (2.6.0-1ubuntu2) ...
Processing triggers for libc-bin ...
ldconfig deferred processing now taking place



Now i try to install libglew1.5 and libglew1.5-dev and etc.
but:



$ sudo apt-get install libglew1.5
Reading package lists... Done
Building dependency tree
Reading state information... Done
libglew1.5 is already the newest version.
0 upgraded, 0 newly installed, 0 to remove and 251 not upgraded.



I try to compile the example from this answer:



#include < GL/glew.h >
#include < GL/glut.h >
#include < GL/gl.h >
#include < GL/glu.h >
#include < GL/glext.h >


GLenum err = glewInit();
if (GLEW_OK != err)
{
fprintf(stderr, "Error %s\n", glewGetErrorString(err));
exit(1);
}
fprintf(stdout, "Status: Using GLEW %s\n", glewGetString(GLEW_VERSION));

if (GLEW_ARB_vertex_program)
fprintf(stdout, "Status: ARB vertex programs available.\n");


if (glewGetExtension("GL_ARB_fragment_program"))
fprintf(stdout, "Status: ARB fragment programs available.\n");

if (glewIsSupported("GL_VERSION_1_4 GL_ARB_point_sprite"))
fprintf(stdout, "Status: ARB point sprites available.\n");


and compile error




$ g++ -lglut -lGL -lGLU -lGLEW example.cpp -o examp
example.cpp:1:23: fatal error: GL/glew.h : No such file or directory
compilation terminated.


enter image description here



Where i can find a normal tutorial for install opengl libs for development? Essential for OpenGL ES...


Answer



Remove the spaces inside the < > and it will compile. So instead of writing < GL/glew.h > write



string - Differences between "abc" + "de" and "abc" + de (de = "de") in Java?



I run the following code and get the results shown in the comments. I know the differences between == and .equals(). What I don't understand is why my code in the second line has different results from the code in the third line.




    String de = "de";
// String abcde = "abc" + "de"; // abcde == "abcde" reture true
String abcde = "abc" + de; // abcde == "abcde" reture false;
System.out.println();
System.out.println(abcde=="abcde");
System.out.println(de=="de");


In trying to debug this I used the javap -c command and got the following output 'code' for the first string concatenation:




         Code:
0: ldc #9; //String de
2: astore_1
3: new #10; //class java/lang/StringBuilder
6: dup
7: invokespecial #11; //Method java/lang/StringBuilder."":()V
10: ldc #4; //String abc
12: invokevirtual #12; //Method java/lang/StringBuilder.append:(Ljava/lang
String;)Ljava/lang/StringBuilder;
15: aload_1

16: invokevirtual #12; //Method java/lang/StringBuilder.append:(Ljava/lang
String;)Ljava/lang/StringBuilder;
19: invokevirtual #13; //Method java/lang/StringBuilder.toString:()Ljava/l
ng/String;
22: astore_2
23: getstatic #14; //Field java/lang/System.out:Ljava/io/PrintStream;
26: invokevirtual #15; //Method java/io/PrintStream.println:()V
29: getstatic #14; //Field java/lang/System.out:Ljava/io/PrintStream;
32: aload_2
33: ldc #16; //String abcde

35: if_acmpne 42
38: iconst_1
39: goto 43
42: iconst_0
43: invokevirtual #17; //Method java/io/PrintStream.println:(Z)V
46: getstatic #14; //Field java/lang/System.out:Ljava/io/PrintStream;
49: aload_1
50: ldc #9; //String de
52: if_acmpne 59
55: iconst_1

56: goto 60
59: iconst_0
60: invokevirtual #17; //Method java/io/PrintStream.println:(Z)V
63: return


And the output for the second string concatenation:






I am not so familiar with this 'code' and can't see any reason why these differences exists. So could anyone explain why those differences happen?



Related post


Answer



The "problem" is simply that the compiler is too smart for you. When it sees "abc" + "de" it immediately concatenates that into the literal "abcde". But when it sees "abc" + de it's not allowed (per Java rules) to "optimize" that to a literal but must instead implement the + function, creating a new String object.



String literals are always handled as interned Strings, so == will work on them.


plot explanation - Banner's control of Hulk in Avengers

During the climatic battle, Banner says 'That's my secret. I'm always angry', and transforms into the Hulk. Does this imply that Banner learned how to control Hulk?


If this is the case, why did he transform during the Helicarrier attack?


Answer


My theory is this:


Banner can already control The Hulk at the beginning of Avengers


This is shown when he is about to show his 'secret' to Black Widow the first time. They are then interrupted (I forget by what already) before he can show her (presumably, his instant transformation). It is then shown (in a very epic fashion) that he can turn into The Hulk at will when the giant Chitauri is approaching them stating to Widow "I'm always angry".


However, when Loki was escaping and caused the floor to pop out from underneath him and Widow, he then loses this control due to the sudden nature of the event and therefore doesn't have full control over The Hulk, hence the battle with Thor.


javascript - function that return a value from ajax call request




I want a function that returns a value from an ajax request. I want to stop javascript execution until the function get its value which is return by ajax asynchronous request.
Something like:



function myFunction() {
var data;
$.ajax({
url: 'url',

data: 'data to send',
success: function (resp) {
data = resp;
},
error: function () {}
}); // ajax asynchronus request
return data; // return data from the ajax request
}

Answer




You need to register a callback function, something like this:



function test() {
myFunction(function(d) {
//processing the data
console.log(d);
});
}

function myFunction(callback) {

var data;
$.ajax({
url: 'url',
data: 'data to send',
success: function (resp) {
data = resp;
callback(data);
},
error: function () {}
}); // ajax asynchronus request

//the following line wouldn't work, since the function returns immediately
//return data; // return data from the ajax request
}

http - PUT vs. POST in REST




According to the HTTP/1.1 Spec:




The POST method is used to request that the origin server accept the entity enclosed in the request as a new subordinate of the resource identified by the Request-URI in the Request-Line




In other words, POST is used to create.




The PUT method requests that the enclosed entity be stored under the supplied Request-URI. If the Request-URI refers to an already existing resource, the enclosed entity SHOULD be considered as a modified version of the one residing on the origin server. If the Request-URI does not point to an existing resource, and that URI is capable of being defined as a new resource by the requesting user agent, the origin server can create the resource with that URI."





That is, PUT is used to create or update.



So, which one should be used to create a resource? Or one needs to support both?


Answer



Overall:



Both PUT and POST can be used for creating.




You have to ask "what are you performing the action to?" to distinguish what you should be using. Let's assume you're designing an API for asking questions. If you want to use POST then you would do that to a list of questions. If you want to use PUT then you would do that to a particular question.



Great both can be used, so which one should I use in my RESTful design:



You do not need to support both PUT and POST.



Which is used is left up to you. But just remember to use the right one depending on what object you are referencing in the request.



Some considerations:





  • Do you name your URL objects you create explicitly, or let the server decide? If you name them then use PUT. If you let the server decide then use POST.

  • PUT is idempotent, so if you PUT an object twice, it has no effect. This is a nice property, so I would use PUT when possible.

  • You can update or create a resource with PUT with the same object URL

  • With POST you can have 2 requests coming in at the same time making modifications to a URL, and they may update different parts of the object.



An example:



I wrote the following as part of another answer on SO regarding this:





POST:



Used to modify and update a resource



POST /questions/ HTTP/1.1
Host: www.example.com/



Note that the following is an error:



POST /questions/ HTTP/1.1
Host: www.example.com/


If the URL is not yet created, you
should not be using POST to create it
while specifying the name. This should
result in a 'resource not found' error

because does not exist
yet. You should PUT the
resource on the server first.



You could though do something like
this to create a resources using POST:



POST /questions HTTP/1.1
Host: www.example.com/



Note that in this case the resource
name is not specified, the new objects
URL path would be returned to you.



PUT:



Used to create a resource, or
overwrite it. While you specify the
resources new URL.




For a new resource:



PUT /questions/ HTTP/1.1
Host: www.example.com/


To overwrite an existing resource:



PUT /questions/ HTTP/1.1

Host: www.example.com/



Additionally, and a bit more concisely, RFC 7231 Section 4.3.4 PUT states (emphasis added),




4.3.4. PUT



The PUT method requests that the state of the target resource be

created or replaced with the state defined by the representation
enclosed in the request message payload.



plot explanation - Why did Peaches&#39; mom hang on the tree? - Movies &amp; TV

In the middle of the movie Ice Age: Continental Drift Peaches' mom asked Peaches to go to sleep. Then, she hung on the tree. This parti...