Saturday, 28 July 2018

character - Voldemort's physical presence pre-Goblet of Fire - Movies & TV

Voldemort returned to physical, human form in the Goblet of Fire. But can someone explain what the physical effects of using the curse on Harry as a baby had on his body? He didn't die but also, wasn't human. What was his state?



Also, when Wormtail put him into the cauldron in HP4, he was nothing more than a small baby-like creature. Where had he been before he was under Wormtail's care? He didn't look capable of taking care of himself or even moving. Was it ever explained where Wormtail actually found him?

c++ - Do the parentheses after the type name make a difference with new?



If 'Test' is an ordinary class, is there any difference between:



Test* test = new Test;


and



Test* test = new Test();


Answer



Let's get pedantic, because there are differences that can actually affect your code's behavior. Much of the following is taken from comments made to an "Old New Thing" article.



Sometimes the memory returned by the new operator will be initialized, and sometimes it won't depending on whether the type you're newing up is a POD (plain old data), or if it's a class that contains POD members and is using a compiler-generated default constructor.




  • In C++1998 there are 2 types of initialization: zero and default

  • In C++2003 a 3rd type of initialization, value initialization was added.




Assume:



struct A { int m; }; // POD
struct B { ~B(); int m; }; // non-POD, compiler generated default ctor
struct C { C() : m() {}; ~C(); int m; }; // non-POD, default-initialising m


In a C++98 compiler, the following should occur:





  • new A - indeterminate value

  • new A() - zero-initialize


  • new B - default construct (B::m is uninitialized)


  • new B() - default construct (B::m is uninitialized)


  • new C - default construct (C::m is zero-initialized)


  • new C() - default construct (C::m is zero-initialized)



In a C++03 conformant compiler, things should work like so:





  • new A - indeterminate value

  • new A() - value-initialize A, which is zero-initialization since it's a POD.


  • new B - default-initializes (leaves B::m uninitialized)


  • new B() - value-initializes B which zero-initializes all fields since its default ctor is compiler generated as opposed to user-defined.


  • new C - default-initializes C, which calls the default ctor.


  • new C() - value-initializes C, which calls the default ctor.




So in all versions of C++ there's a difference between new A and new A() because A is a POD.



And there's a difference in behavior between C++98 and C++03 for the case new B().



This is one of the dusty corners of C++ that can drive you crazy. When constructing an object, sometimes you want/need the parens, sometimes you absolutely cannot have them, and sometimes it doesn't matter.


java - .nextLine() method does not take subsequent String inputs





I have a program that asks the user for an input of numbers and characters. For this I am using a Scanner class. But when I take two subsequent string inputs, the console just moves and asks the user to input the second string. The user is unable to input the first string. I have attached my code below to be more specific.



import java.util.Scanner;

class XYZ {


public static void main(String args[]) {
int x, y, z, b, c;
String p, q;
Scanner sc = new Scanner(System.in);

System.out.println("Enter a number");
b = sc.nextInt();

System.out.println("Enter a new number");
c = sc.nextInt();


System.out.println("Enter a String");
p = sc.nextLine();

System.out.println("Enter a new String");
q = sc.nextLine();

System.out.println("Enter a number");
x = sc.nextInt();


System.out.println("Enter 2nd number");
y = sc.nextInt();

System.out.println("Enter 3rd number");
z = sc.nextInt();

ABC a = new ABC();

a.PQR(b, c);
a.PQR(p, q);

a.PQR(x, y, z);
}
}

class ABC {

void PQR(int a, int b) {
int res = a + b;
System.out.println("The sum is" + " " + res);
}


void PQR(String a, String b) {
System.out.println("Thye concataneted string is" + a + " " + b);
}

void PQR(int a, int b, int c) {
int res = a * b * c;
System.out.println("The product is" + " " + res);
}
}


Answer



You need to make a dummy call to nextLine() after your call to nextInt(). The nextInt() isn't taking the "\n" into account.



Alternatively, and preferably, just use nextLine() to accept all input and whichever ones need to be ints, just use:



int i = Integer.parseInt(**string**);


Does this help?



'arrested-development' tag wiki - Movies & TV



Television show, previously of the Fox Television Network, recently NetFlix, and a proposed movie, detailing the events of a jailed Real Estate patriarch and the comedic efforts of his family to maintain the business in his absence.






There is no tag wiki for this tag … yet!




Tag wikis help introduce newcomers to the tag. They contain an overview of the topic defined by the tag, along with guidelines on its usage.



All registered users may propose new tag wikis.



(Note that if you have less than 20000 reputation, your tag wiki will be peer reviewed before it is published.)


c# - Enum String Name from Value




I have an enum construct like this:



public enum EnumDisplayStatus
{
None = 1,
Visible = 2,
Hidden = 3,
MarkedForDeletion = 4
}



In my database, the enumerations are referenced by value. My question is, how can I turn the number representation of the enum back to the string name.



For example, given 2 the result should be Visible.


Answer



You can convert the int back to an enumeration member with a simple cast, and then call ToString():



int value = GetValueFromDb();
var enumDisplayStatus = (EnumDisplayStatus)value;
string stringValue = enumDisplayStatus.ToString();


c# - DataGridView displays empty cells when bound to typed DataTable

I'm creating a simple application that simply populates a DataGridView with a strongly typed DataTable. My problem is that all the cells show up empty despite containing data, I have a CellDoubleClick event which can pick up the underlying value of the cell (which is typed as expected) but the column is shown as empty.


Objects of type INode all have a ToString() method defined and my assumption was that the DataGridView would be intelligent enough to call that method any show that as the cell contents but it appears not.


Here is my current test code:


        //Add some fake test data
DataTable data = new DataTable();
data.Columns.Add("Subject");
data.Columns.Add("Predicate");
data.Columns.Add("Object");
data.Columns["Subject"].DataType = typeof(INode);
data.Columns["Predicate"].DataType = typeof(INode);
data.Columns["Object"].DataType = typeof(INode);
Graph g = new Graph();
DataRow row = data.NewRow();
row["Subject"] = g.CreateURINode(new Uri("http://example.org/subject"));
row["Predicate"] = g.CreateURINode(new Uri("http://example.org/predicate"));
row["Object"] = g.CreateURINode(new Uri("http://example.org/object"));
data.Rows.Add(row);
this.dvwBrowser.DataSource = data;
this.dvwBrowser.AutoResizeColumns();

How can I get the value of the ToString() method to be displayed in the cells when I bind the DataTable to the DataGridView?

python - How do I pass a variable by reference?



The Python documentation seems unclear about whether parameters are passed by reference or value, and the following code produces the unchanged value 'Original'



class PassByReference:
def __init__(self):
self.variable = 'Original'
self.change(self.variable)
print(self.variable)


def change(self, var):
var = 'Changed'


Is there something I can do to pass the variable by actual reference?


Answer



Arguments are passed by assignment. The rationale behind this is twofold:




  1. the parameter passed in is actually a reference to an object (but the reference is passed by value)


  2. some data types are mutable, but others aren't



So:




  • If you pass a mutable object into a method, the method gets a reference to that same object and you can mutate it to your heart's delight, but if you rebind the reference in the method, the outer scope will know nothing about it, and after you're done, the outer reference will still point at the original object.


  • If you pass an immutable object to a method, you still can't rebind the outer reference, and you can't even mutate the object.





To make it even more clear, let's have some examples.



List - a mutable type



Let's try to modify the list that was passed to a method:



def try_to_change_list_contents(the_list):
print('got', the_list)
the_list.append('four')
print('changed to', the_list)


outer_list = ['one', 'two', 'three']

print('before, outer_list =', outer_list)
try_to_change_list_contents(outer_list)
print('after, outer_list =', outer_list)


Output:




before, outer_list = ['one', 'two', 'three']
got ['one', 'two', 'three']
changed to ['one', 'two', 'three', 'four']
after, outer_list = ['one', 'two', 'three', 'four']


Since the parameter passed in is a reference to outer_list, not a copy of it, we can use the mutating list methods to change it and have the changes reflected in the outer scope.



Now let's see what happens when we try to change the reference that was passed in as a parameter:




def try_to_change_list_reference(the_list):
print('got', the_list)
the_list = ['and', 'we', 'can', 'not', 'lie']
print('set to', the_list)

outer_list = ['we', 'like', 'proper', 'English']

print('before, outer_list =', outer_list)
try_to_change_list_reference(outer_list)
print('after, outer_list =', outer_list)



Output:



before, outer_list = ['we', 'like', 'proper', 'English']
got ['we', 'like', 'proper', 'English']
set to ['and', 'we', 'can', 'not', 'lie']
after, outer_list = ['we', 'like', 'proper', 'English']



Since the the_list parameter was passed by value, assigning a new list to it had no effect that the code outside the method could see. The the_list was a copy of the outer_list reference, and we had the_list point to a new list, but there was no way to change where outer_list pointed.



String - an immutable type



It's immutable, so there's nothing we can do to change the contents of the string



Now, let's try to change the reference



def try_to_change_string_reference(the_string):
print('got', the_string)

the_string = 'In a kingdom by the sea'
print('set to', the_string)

outer_string = 'It was many and many a year ago'

print('before, outer_string =', outer_string)
try_to_change_string_reference(outer_string)
print('after, outer_string =', outer_string)



Output:



before, outer_string = It was many and many a year ago
got It was many and many a year ago
set to In a kingdom by the sea
after, outer_string = It was many and many a year ago


Again, since the the_string parameter was passed by value, assigning a new string to it had no effect that the code outside the method could see. The the_string was a copy of the outer_string reference, and we had the_string point to a new string, but there was no way to change where outer_string pointed.




I hope this clears things up a little.



EDIT: It's been noted that this doesn't answer the question that @David originally asked, "Is there something I can do to pass the variable by actual reference?". Let's work on that.



How do we get around this?



As @Andrea's answer shows, you could return the new value. This doesn't change the way things are passed in, but does let you get the information you want back out:



def return_a_whole_new_string(the_string):
new_string = something_to_do_with_the_old_string(the_string)

return new_string

# then you could call it like
my_string = return_a_whole_new_string(my_string)


If you really wanted to avoid using a return value, you could create a class to hold your value and pass it into the function or use an existing class, like a list:



def use_a_wrapper_to_simulate_pass_by_reference(stuff_to_change):
new_string = something_to_do_with_the_old_string(stuff_to_change[0])

stuff_to_change[0] = new_string

# then you could call it like
wrapper = [my_string]
use_a_wrapper_to_simulate_pass_by_reference(wrapper)

do_something_with(wrapper[0])


Although this seems a little cumbersome.



php - file_get_contents shows unexpected output while reading a file

I want to output an inline jpg image as a base64 encoded string, however when I do this : $contents = file_get_contents($filename); print ...