Jump to content
#FlattenTheCurve ×

waslsdnowlds

New Members
  • Content Count

    9
  • Joined

  • Last visited

Community Reputation

0 Neutral

About waslsdnowlds

  • Rank
    Newbie
  1. I have an installation that needs to delete the install folder after install is completed. It deletes all files in the directory, then removes the directory. So, what I've done so far is the following below. sudo groupadd -g 5252 website sudo usermod -g website www-data sudo usermod -g website ubuntu sudo usermod -g website root sudo chgrp website var/www/ sudo chgrp website var/www/html/ sudo chmod 775 var/www/ -R sudo chmod 775 var/www/html -R sudo chmod g+s var/www/ -R sudo chmod g+s var/www/html -R sudo setfacl -dm g::rwX var/www/ sudo setfacl -dm g::rwX var/www/html sudo setfacl -dm o::rX var/www/ sudo setfacl -dm o::rX var/www/html Yet, all my files upload via FTP have a rw-rw-rw- permission. The folders have a drwxrwsrwx. So, weird.
  2. When anything new is placed in the var/www/html directory via sftp using the ubuntu user.
  3. I've written some code to remove a directory using rmdir. Yes, the line above it removes the files inside that folder. I know the code works on different servers. I believe the issue lies in how I set up my Ubuntu server (via AWS). To sftp I use the user ubuntu to put all my files into var/www/html. Then in mysql, I'm using root for everything including connecting to the database via root. When my code attempts to remove a directory, it cannot due to permissions. I know this because I have to set the permissions to 777 to get the code to remove it. Then when anything new is placed into the var/www/html (which ive also chmod to 777), I still need to chmod anything new placed into that directory. Hope this makes sense. Where do I go from here? I don't understand why my code cannot delete files within the var/www/html without me having to ssh and chmod whatever needs to be deleted. Perhaps, it's because Ubuntu user dropped them via sftp in instead of root?
  4. I don't completely understand this code. I'm trying to grasp my mind around it. I get what it returns (7) but I don't understand that if($$v++) part. $$v++ I'm guessing compares the current $v to the next value in the array creating a new variable $$v? Is that right? function fdup($a){ foreach($a as $v) if($$v++) return $v; return -1; } $a = array(10, 6, 7, 4, 9, 1, 7, 2, 5, 3); fdup($a);
  5. function firstDuplicate($a){ $duplicates = array_diff_assoc($a, array_unique($a)); return count($duplicates) > 0 ? array_shift($duplicates) : -1; }
  6. Nice, Barand. That works. One of the requirements is to have return a -1 if nothing is found. I did just that. function firstDuplicate($arr){ foreach ($arr as $k=>$n) { $subarr = array_slice($arr,0,$k); if (in_array($n, $subarr)) return $n; } return -1; } The issue is I'm still getting the following issue: Program exceeded the execution time limit. Make sure that it completes execution in a few seconds for any possible input. Any ideas on that?
  7. This code is functioning but the execution time limit exceeds what is requested. I've downed it a little bit but it seems it needs to be even faster. Any ideas? function firstDuplicate($array){ $stored_value = -1; $stored_index = count($array); for($current_index = 0; $current_index < count($array); $current_index++){ $current_value = $array[$current_index]; $comparing_index = $current_index+1; for($comparing_index; $comparing_index < count($array); $comparing_index++){ $comparing_value = $array[$comparing_index]; if ($current_value === $comparing_value && $comparing_index < $stored_index){ $stored_value = $current_value; $stored_index = $comparing_index; } } } if ($stored_index != count($array)){ return $stored_value; } else { return -1; } } $a = array(8, 4, 6, 2, 6, 4, 7, 9, 5, ; firstDuplicate($a); Results 6
  8. Thanks for the suggestions. While I was waiting for someone to reply I found this to give me the first duplicate. Any suggestions on making the code smaller? $array = array(1,2,3,5,5,7,8,; for($current_index = 0; $current_index < count($array)-1; $current_index++){ $current_value = $array[$current_index]; $next_index = $current_index+1; for($comparing_index = $next_index; $comparing_index < count($array)-1; $comparing_index++){ $comparing_value = $array[$comparing_index]; if ($current_value != $comparing_value){ } else { echo "First Duplicate: $current_value"; return; } } } Results First Duplicate: 5
  9. I'm trying to create some code that finds the first duplicate of an array and echo's it out. I've been working about two hours on this bad boy and have got to this point. Code and results are below. Any suggestions on why the 5 skips the next 5? $array = array(1,2,3,5,5,7,; for($current_index = 0; $current_index < count($array); $current_index++){ $current_value = $array[$current_index]; $next_index = $current_value; for($comparing_index = $next_index; $comparing_index < count($array); $comparing_index++){ $comparing_value = $array[$comparing_index]; if ($current_value != $comparing_value){ echo "$current_value does not equal $comparing_value<br>"; } else { echo "$current_value equals $comparing_value"; break; } } } Results 1 does not equal 2 1 does not equal 3 1 does not equal 5 1 does not equal 5 1 does not equal 7 1 does not equal 8 2 does not equal 3 2 does not equal 5 2 does not equal 5 2 does not equal 7 2 does not equal 8 3 does not equal 5 3 does not equal 5 3 does not equal 7 3 does not equal 8 5 does not equal 7 5 does not equal 8 5 does not equal 7 5 does not equal 8
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.