Monday, August 5, 2019

plot explanation - Why did Peaches' mom hang on the tree? - Movies & 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 particular scene was quite strange and confused me pretty badly, because she's a mammoth, why did she hang on the tree like that?




Further, I've only watched the Ice Age3 and Ice Age4. Did I miss anything? Did they show any scene towards Peaches' mom's strange behavior in the previous parts?


Answer



In Ice Age 2, when Elle was first introduced, she thought she was a possum, thus hanging upside down in a tree to sleep. Some of her habits were taught to Peaches, thus the girl sleeping upside down.



In Ice Age 4, there was a line of dialogue from Peaches about being half possum. this came from the idea that Elle still believes herself to be a possum, but that Peaches' dad is a mammoth.


Sunday, August 4, 2019

Delete /n at end of a String (Python)





How can I delete a /n linebreak at the end of a String ?



I´m trying to read two strings from an .txt file and want to format them with os.path.join() method after I "cleared" the string.



Here you can see my try with dummy data:



content = ['Source=C:\\Users\\app\n', 'Target=C:\\Apache24\\htdocs']

for string in content:
print(string)

if string.endswith('\\\n'):
string = string[0:-2]

print(content)

Answer



You can not update a string like you are trying to. Python strings are immutable. Every time you change a string, new instance is created. But, your list still refers to the old object. So, you can create a new list to hold updated strings. And to strip newlines you can use rstrip function. Have a look at the code below,



content = ['Source=C:\\Users\\app\n', 'Target=C:\\Apache24\\htdocs']
updated = []

for string in content:
print(string)
updated.append(string.rstrip())

print(updated)

java - How to sort a map

For starters, you will need to be using an instance of SortedMap. If the map doesn't implement that interface, then it has an undefined/arbitrary iteration order and you can't control it. (Generally this is the case, since a map is a way of associating values with keys; ordering is an auxiliary concern.)


So I'll assume you're using TreeMap, which is the canonical sorted map implementation. This sorts its keys according to a Comparator which you can supply in the constructor. So if you can write such a comparator that determines which is the "lower" of two arbitrary keys (spoiler alert: you can), this will be straightforward to implement.


This will, however, only work when sorting by key. I don't know if it makes much sense to sort a map by value, and I'm not aware of any straightforward way to do this. The best I can think of is to write a Comparator that sorts on values, call Map.getEntrySet and push all the entries into a list, then call Collections.sort on the list. It's not very elegant or efficient but it should get the job done if performance isn't your primary concern.


(Note also that if your keys aren't immutable, you will run into a lot of trouble, as they won't be resorted when externally changed.

plot explanation - Why did the girl try to kill herself in the 2009 Sherlock Holmes film?

In the beginning of Sherlock Holmes (2009), Lord Blackwood attempts to kill a young woman during some sort of dark ritual and is thwarted just in time by Holmes and Watson. Blackwood himself was not going to do it, instead he put her in some sort of "spell", causing the girl to attempt to stab herself.


woman in a white dress laying on a slab with a black hooded figure standing at the head of the slab


Given that the "supernatural powers" of Lord Blackwood were revealed as nothing more than "conjuring tricks", why did the girl try to stab herself at the direction of Blackwood?


Answer


I never saw a definitive explanation, but there are three theories:



  1. Hypnotism (a person with Blackwood's personality and charisma is likely to be a good hypnotist). This is somewhat confirmed by the script (after Holmes stops Blackwood):



    The girl has snapped out of her trance, and is backing away from them as best she can



  2. Somewhat related to the first possibility, please note that the cult members frequently allow the cult leader to exercise nearly total control, up to suicide (see Jim Jones for one of the more dramatic examples, that gave name to the "drinking cool-aid" expression).


    Also, while extremely rare in actuality, sacrifice has happened on the more extreme end of BDSM circles and is an unexpectedly popular thing for many in BDSM as a fantasy.


  3. The "victim" was an actress who was supposed to act like she was about to kill herself, considering that Blackwood pretty much arranged for his own arrest.



AWK print next line of match between matches

Let's presume I have file test.txt with following data:



.0

41
0.0
42
0.0
43
0.0
44
0.0
45
0.0

46
0.0
START
90
34
17
34
10
100
20

2056
30
0.0
10
53
20
2345
30
0.0
10

45
20
875
30
0.0
END
0.0
48
0.0
49

0.0
140
0.0


With AWK how would I print the lines after 10 and 20 between START and END.
So the output would be.



100
2056

53
2345
45
875


I was able to get the lines with 10 and 20 with



awk '/START/,/END/ {if($0==10 || $0==20) print $0}' test.txt 



but how would I get the next lines?

mysql - How to restrict update or insert more than once by navigating back to referring page in php?




I am developing a web application where I want to restrict update or insert more than once by navigating back to referring page. Let me present you three model files in the order of flow so that I can raise the zone where I am stuck.




  • register.html



            
    ...






    ...


  • process.php



                    echo "Welcome ".$_GET['para'];
    ?>


  • success.php



                    if(isset($_POST['Submit']))
    {
    $name = $_POST['name'];

    // some database update here ...


    echo "Done. Click to go next";
    unset($_POST['Submit']);
    }else{
    echo "Error in submission";
    }
    ?>



The above three files are very simple. Here the update part has nothing to do when the user hits the back button after landing on page success.php because of unset($_POST['Submit']);. But when the user goes back further by hitting the back button again it reaches register.html and can again come up with the $_POST['Submit'] set and may do the update part which is sometimes vulnerable. I know there is Post/Redirect/Get to solve this issue, but I want some other alternatives so that the part gatekeepering the update part may be made so efficient that it would not allow the same anymore by clicking the back button.



Answer



If you are getting duplicate records inserted.




  1. You may try INSERT IGNORE

  2. ADD UNIQUE INDEX to your table to prevent this happening



    you may choose any one of INSERT IGNORE and REPLACE according to the duplicate-handling behavior





Refer https://dev.mysql.com/doc/refman/5.5/en/insert-on-duplicate.html




  1. Lastly you may like simple php with mysqli_num_rows()



    $sql = "SELECT id FROM table-name WHERE column-name1 = ? AND column-name2 = ? ;
    $mq = mysqli_query($sql);

    if (mysqli_num_rows($mq) < 1) {
    $sql = "UPDATE table-name SET (colum-names) VALUES (...)";

    mysqli_query($sql);
    else {
    echo "Record already updated";
    }
    }


sharedpreferences - How to delete shared preferences data from App in Android

None of the answers work for me since I have many shared preferences keys.



Let's say you are running an Android Test instead of a unit test.



It is working for me loop and delete through all the shared_prefs files.




@BeforeClass will run before all the tests and ActivityTestRule





@BeforeClass
public static void setUp() {
Context context = InstrumentationRegistry.getTargetContext();

File root = context.getFilesDir().getParentFile();
String[] sharedPreferencesFileNames = new File(root, "shared_prefs").list();
for (String fileName : sharedPreferencesFileNames) {
context.getSharedPreferences(fileName.replace(".xml", ""), Context.MODE_PRIVATE).edit().clear().commit();
}

}

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...