This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Validator::extend('youtube', function ($attribute, $value, $parameters, $validator) { | |
preg_match("#(?<=v=)[a-zA-Z0-9-]+(?=&)|(?<=v\/)[^&\n]+(?=\?)|(?<=v=)[^&\n]+|(?<=youtu.be/)[^&\n]+#", $value, $matches); | |
return count($matches) > 0; | |
}, "Sorry, this doesn't look like a valid youtube URL"); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function diagonalDifference($arr) { | |
$diagAc = []; | |
$diagBd = []; | |
$arrMain_len = count($arr); | |
foreach ($arr as $key => $arrSub) { | |
$arrSub_len = count($arrSub); | |
if ($arrMain_len == $arrSub_len) { | |
$diagAc[] = $arrSub[$key]; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function plusMinus($arr) { | |
$arrLen = count($arr); | |
$posi = count(array_filter($arr, "countPosi")); | |
$nega = count(array_filter($arr, "countNega")); | |
$zero = count(array_filter($arr, "countZero")); | |
$ratioPosi = $posi / $arrLen; | |
$ratioNega = $nega / $arrLen; | |
$ratioZero = $zero / $arrLen; | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function staircase($n) { | |
for ($i = 0; $i < $n; $i++) { | |
echo str_repeat(" ", ($n - $i -1)). str_repeat("#", ($i + 1)) . "\n"; | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function miniMaxSum($arr) { | |
$minArr = min($arr); | |
$maxArr = max($arr); | |
if ($minArr !== $maxArr) { | |
$miniSum = array_sum(array_diff($arr, [$maxArr])); | |
$maxSum = array_sum(array_diff($arr, [$minArr])); | |
} else { | |
// Case 13: 5 elements are the sames | |
unset($arr[0]); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function birthdayCakeCandles($ar) { | |
$candles = array_count_values($ar); | |
ksort($candles); | |
$candleLast = array_key_last($candles); | |
$tallestCandels = $candles[$candleLast]; | |
return $tallestCandels; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function timeConversion($s) { | |
return date("H:i:s", strtotime($s)); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function vowelsAndConsonants(s) { | |
let vowels = ['a', 'e', 'i', 'o', 'u']; | |
let sLen = s.length; | |
for (let i = 0; i < sLen; i++) { | |
if (vowels.includes(s[i])) { | |
console.log(s[i]); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
server { | |
listen 80; | |
server_name main_domain.com www.main_domain.com; | |
return 301 https://$server_name$request_uri; | |
} | |
server { | |
listen 443 ssl default_server; | |
# access_log off; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
sync; echo 3 > /proc/sys/vm/drop_caches | |
## setup crontab */30 * * * * /usr/bin/bash /home/cronjob/cache-clear.sh |
OlderNewer