Tuesday, 1 August 2017

analysis - What does the title of The Discreet Charm of the Bourgeoisie mean, especially the Discreet Charm part? - Movies & TV

This 1972 movie, co-written and directed by the surrealist Luis Bunuel. I never actually get what is this the title about, especially "discreet charm".




Foremost, why is it "discreet"? Secondly, is the word "charm" used ironically, since some may find this movie freaky even without making any extra connection of what it is about.



Then, what does "discreet charm" mean together?
From here I think I could figure out the rest, but more explanation is always welcome. <;)

html - autocomplete attribute is not passing XHTML 1.0 Transitional validation, why?




I'm trying to cleanup my xhtml validation -- I'm running my pages through the W3C validator. For some puzzling reason it's not passing on input fields with the autocomplete="off" attribute:



            onblur="if(this.value=='')this.value=this.defaultValue;" class="searchbox" value="Search" />


I'm using this doctype:








And this is the validation error:



Line 410, Column 81: there is no attribute "autocomplete"



…li_search_1" type="text" autocomplete="off" onfocus="if(this.defaultValue==thi…



I thought this was okay with the W3C -- but, maybe it's still in "submission" phase?
http://www.w3.org/Submission/web-forms2/#autocomplete




Thoughts?


Answer



The Web forms specification has nothing to do with HTML 4 / XHTML. Sadly, autocomplete will not pass validation.



I think the only way to achieve valid HTML 4 /XHTML with autocomplete turned off is adding the attribute on page load using JavaScript. Sucks, I know - but I think it's the only way.


[unable to retrieve full-text content]

multithreading - Working on a java based chatting application using threading

I was trying to send message through threading. dataAvailable is a variable which tells whether message is available on textfield or not. if available dataAvailable is set to true and in run() method if it is true following code is executed. But the problem is in run() it never sees dataAvailable is true and nothing is sent. Help needed.




/*

This is client


*/
import java.awt.BorderLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.net.Socket;
import java.net.UnknownHostException;

import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JScrollPane;
import javax.swing.JTextArea;
import javax.swing.JTextField;

public class PeerOne extends JFrame implements Runnable
{
private static final long serialVersionUID = 1L;


JTextField outgoing;
JTextArea incoming;
JButton send;
Thread t,t1;
ObjectOutputStream output; //for writing objects to a stream
ObjectInputStream input; //for reading objects from a stream
Socket s;
volatile boolean dataAvailable=false;
String message = null;
public PeerOne()

{
outgoing = new JTextField();
outgoing.setEnabled(true);
outgoing.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
if(!(e.getActionCommand().isEmpty()))
{
dataAvailable = true;
System.out.print("hi");
}

}
});

this.add(outgoing,BorderLayout.SOUTH);

incoming = new JTextArea();
incoming.setEditable(true);
this.add(new JScrollPane(incoming),BorderLayout.CENTER);
this.add(incoming);


setSize(300,150);
setVisible(true);

try
{
s = new Socket("localhost",5500);
incoming.append("Connection Successfull..."+"\n");

output = new ObjectOutputStream(s.getOutputStream());
output.flush();

input = new ObjectInputStream(s.getInputStream());

}
catch (UnknownHostException e)
{
e.printStackTrace();
}
catch (IOException e)
{
e.printStackTrace();

}

t = new Thread(this,"PeerOne");
System.out.print("New Thread");
//t1 = new Thread(this,"Two");
t.start();
}

public static void main(String[] args)
{

new PeerOne();
}

public void run()
{
while(true)
{
if(dataAvailable==true)
{
try

{
System.out.print(0);
output.writeObject(outgoing.getText());
output.flush();
dataAvailable = false;
}
catch (IOException e1)
{
e1.printStackTrace();
}

}
try
{
try
{
message = (String)input.readObject();

incoming.append(message);
}
catch (ClassNotFoundException e)

{
e.printStackTrace();
}
} catch (IOException e) {
e.printStackTrace();
}
}

}
}





/*

This is server

*/
import java.awt.BorderLayout;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.BufferedInputStream;
import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.io.PrintStream;
import java.net.ServerSocket;
import java.net.Socket;
import java.net.UnknownHostException;


import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JScrollPane;
import javax.swing.JTextArea;
import javax.swing.JTextField;

public class PeerTwo extends JFrame implements Runnable
{
private static final long serialVersionUID = 1L;

JTextField outgoing;
JTextArea incoming;
JButton send;
Thread t;
Socket s;
ObjectOutputStream output; //for writing objects to a stream
ObjectInputStream input; //for reading objects from a stream
volatile boolean dataAvailable=false;
String message = null;


public PeerTwo()
{
outgoing = new JTextField();
outgoing.setEnabled(true);
outgoing.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
if(!(e.getActionCommand().isEmpty()))
{
dataAvailable = true;
}

}
});

this.add(outgoing,BorderLayout.SOUTH);

incoming = new JTextArea();
incoming.setEditable(true);
this.add(new JScrollPane(incoming),BorderLayout.CENTER);
this.add(incoming);


setSize(300,150);
setVisible(true);
try
{
ServerSocket ss = new ServerSocket(5500,100);
s = ss.accept();

output = new ObjectOutputStream(s.getOutputStream());
output.flush();
input = new ObjectInputStream(s.getInputStream());

}
catch (UnknownHostException e)
{
e.printStackTrace();
}
catch (IOException e)
{
e.printStackTrace();
}


t = new Thread(this,"PeerTwo");
System.out.print("New Thread");
t.start();



}

public static void main(String[] args)
{

new PeerTwo();
}

public void run()
{
while(true)
{
if(dataAvailable==true)
{
try

{
System.out.print("bbb");
output.writeObject(outgoing.getText());
output.flush();
dataAvailable = false;
}
catch (IOException e1)
{
e1.printStackTrace();
}

}
try {
try
{
message = (String)input.readObject();
System.out.print(0);
incoming.append(message);
}
catch (ClassNotFoundException e)
{

e.printStackTrace();
}
} catch (IOException e) {
e.printStackTrace();
}
}
}
}

javascript - Why does ++[[]][+[]]+[+[]] return the string "10"?



This is valid and returns the string "10" in JavaScript (more examples here):






console.log(++[[]][+[]]+[+[]])





Why? What is happening here?


Answer



If we split it up, the mess is equal to:



++[[]][+[]]

+
[+[]]


In JavaScript, it is true that +[] === 0. + converts something into a number, and in this case it will come down to +"" or 0 (see specification details below).



Therefore, we can simplify it (++ has precendence over +):



++[[]][0]
+

[0]


Because [[]][0] means: get the first element from [[]], it is true that:



[[]][0] returns the inner array ([]). Due to references it's wrong to say [[]][0] === [], but let's call the inner array A to avoid the wrong notation.



++ before its operand means “increment by one and return the incremented result”. So ++[[]][0] is equivalent to Number(A) + 1 (or +A + 1).



Again, we can simplify the mess into something more legible. Let's substitute [] back for A:




(+[] + 1)
+
[0]


Before +[] can coerce the array into the number 0, it needs to be coerced into a string first, which is "", again. Finally, 1 is added, which results in 1.




  • (+[] + 1) === (+"" + 1)


  • (+"" + 1) === (0 + 1)

  • (0 + 1) === 1



Let's simplify it even more:



1
+
[0]



Also, this is true in JavaScript: [0] == "0", because it's joining an array with one element. Joining will concatenate the elements separated by ,. With one element, you can deduce that this logic will result in the first element itself.



In this case, + sees two operands: a number and an array. It’s now trying to coerce the two into the same type. First, the array is coerced into the string "0", next, the number is coerced into a string ("1"). Number + String === String.



"1" + "0" === "10" // Yay!






Specification details for +[]:



This is quite a maze, but to do +[], first it is being converted to a string because that's what + says:




11.4.6 Unary + Operator



The unary + operator converts its operand to Number type.



The production UnaryExpression : + UnaryExpression is evaluated as follows:





  1. Let expr be the result of evaluating UnaryExpression.


  2. Return ToNumber(GetValue(expr)).





ToNumber() says:





Object



Apply the following steps:




  1. Let primValue be ToPrimitive(input argument, hint String).


  2. Return ToString(primValue).






ToPrimitive() says:




Object



Return a default value for the Object. The default value of an object is retrieved by calling the [[DefaultValue]] internal method of the object, passing the optional hint PreferredType. The behaviour of the [[DefaultValue]] internal method is defined by this specification for all native ECMAScript objects in 8.12.8.




[[DefaultValue]] says:





8.12.8 [[DefaultValue]] (hint)



When the [[DefaultValue]] internal method of O is called with hint String, the following steps are taken:




  1. Let toString be the result of calling the [[Get]] internal method of object O with argument "toString".


  2. If IsCallable(toString) is true then,





a. Let str be the result of calling the [[Call]] internal method of toString, with O as the this value and an empty argument list.



b. If str is a primitive value, return str.




The .toString of an array says:




15.4.4.2 Array.prototype.toString ( )




When the toString method is called, the following steps are taken:




  1. Let array be the result of calling ToObject on the this value.


  2. Let func be the result of calling the [[Get]] internal method of array with argument "join".


  3. If IsCallable(func) is false, then let func be the standard built-in method Object.prototype.toString (15.2.4.2).


  4. Return the result of calling the [[Call]] internal method of func providing array as the this value and an empty arguments list.






So +[] comes down to +"", because [].join() === "".



Again, the + is defined as:




11.4.6 Unary + Operator



The unary + operator converts its operand to Number type.



The production UnaryExpression : + UnaryExpression is evaluated as follows:





  1. Let expr be the result of evaluating UnaryExpression.


  2. Return ToNumber(GetValue(expr)).





ToNumber is defined for "" as:





The MV of StringNumericLiteral ::: [empty] is 0.




So +"" === 0, and thus +[] === 0.


php - .htaccess issue with folder

I have an .htaccess file in my root directory with the following contents:



RewriteEngine On
RewriteCond %{SERVER_PORT} 80
RewriteRule ^(.*)$ https://website.com/$1 [R=301,L]
DirectoryIndex index.php
Options -Indexes



Works perfect in the root.



The problem is with subfolders. If I manually go to:
http://www.website.com/myfolder
it pushes me to:
https://website.com/myfolder/.php (404 error)



My goal is to always remove the "www" and redirect to SSL for the root and all subfolders. Obviously without the above error where it somehow leaves the ".php"



Please help!




Thanks!

c++ - Ambiguous operator overload on clang



When I try to compile this test program:



struct comma_guard
{

template
const comma_guard& operator,(T&&) const
{
return *this;
}
};

struct foo {};
template T operator,(T x, foo)
{

return x;
}

int main()
{
(comma_guard(), foo());
}


I get a compile error on clang:




comma_guard.cpp:20:19: error: use of overloaded operator ',' is ambiguous (with operand types 'comma_guard' and 'foo')
(comma_guard(), foo());
~~~~~~~~~~~~~^ ~~~~~
comma_guard.cpp:6:24: note: candidate function [with T = foo]
const comma_guard& operator,(T&&) const
^
comma_guard.cpp:13:21: note: candidate function [with T = comma_guard]
template T operator,(T x, foo)
^



This compiles fine on gcc. From my understanding of ADL lookup, the member function in comma_guard should be preferred and so therefore shouldn't be ambiguous. Is this correct? Is this a bug in clang? Also, is there a workaround so that the operator in comma_guard will always be preferred?



Update: So it seems clang doesn't consider it a class member when its templated. So if I define the comma_guard like this, it will work:



struct comma_guard
{
struct any
{

template
any(T&&);
};
const comma_guard& operator,(any) const;
};


Which is correct according to C++?


Answer





From my understanding of ADL lookup, the member function in comma_guard should be preferred and so therefore shouldn't be ambiguous. Is this correct?







Answer: During overload resolution and according to the standard § 13.3.1/2 & 7 Candidate functions and argument lists [over.match.funcs]:




2 The set of candidate functions can contain both member and non-member functions to be resolved against the same argument list.




7 In each case where a candidate is a function template, candidate function template specializations are generated using template argument deduction (14.8.3, 14.8.2). Those candidates are then handled as candidate functions in the usual way [126].



[footnote 126] The process of argument deduction fully determines the parameter types of the function template specializations, i.e., the parameters of function template specializations contain no template parameter types. Therefore, except where specified
otherwise, function template specializations and non-template functions (8.3.5) are treated equivalently for the remainder of overload resolution.




Consequently, the template member overloaded operator hasn't have greater priority in terms of overload resolution picking than the template free overloaded operator.



Even if it had GCC picks the free template overloaded operator LIVE DEMO.




So in my humble opinion, here is GCC that shows a non standard compliant behaviour and Clang rightfully complains about overload resolution ambiguity.







Also, is there a workaround so that the operator in comma_guard will always be preferred?








Answer: Yes although kinda ugly: (comma_guard().operator,(foo())); LIVE DEMO


casting - Why wasn&#39;t Tobey Maguire in The Amazing Spider-Man? - Movies &amp; TV

In the Spider-Man franchise, Tobey Maguire is an outstanding performer as a Spider-Man and also reprised his role in the sequels Spider-Man...