Last active
June 24, 2020 15:33
-
-
Save horlathunbhosun/5b971fbfc85640acbfcb54aa37d0134c to your computer and use it in GitHub Desktop.
Mail
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
<?php | |
$handle = fopen ("php://stdin", "r"); | |
function compareTriplets($a0, $a1, $a2, $b0, $b1, $b2){ | |
// Complete this function | |
$alice = 0; | |
$bob = 0; | |
$alice += ($a0 > $b0? 1:0) + ($a1 > $b1? 1:0) + ($a2 > $b2? 1:0); | |
$bob += ($b0 > $a0? 1:0) + ($b1 > $a1? 1:0) + ($b2 > $a2? 1:0); | |
$score = array(); | |
array_push($score,$alice,$bob); | |
return $score; | |
} | |
fscanf($handle, "%d %d %d", $a0, $a1, $a2); | |
fscanf($handle, "%d %d %d", $b0, $b1, $b2); | |
$result = compareTriplets($a0, $a1, $a2, $b0, $b1, $b2); | |
echo implode(" ", $result)."\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
<?php | |
namespace App\Http\Controllers; | |
use Illuminate\Http\Request; | |
use Illuminate\Support\Facades\Http; | |
class EmailValidator extends Controller | |
{ | |
// | |
/** | |
* check if email is valid from mailboxlayer.com API register to get the key | |
* @param Request $request | |
*/ | |
public function checkEmailValidity(Request $request) | |
{ | |
$client = new \GuzzleHttp\Client(); | |
$request->validate([ | |
'email' => 'required|email' | |
]); | |
$email = $request->get('email'); | |
$accessKey = ""; | |
$response = $client->post('http://apilayer.net/api/check?access_key='. $accessKey. '&email='.$email. '&format=1'); | |
return $response->getBody(); | |
} | |
} |
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
If you have to run an every minute recurring job (lots of checks and user processing here) for | |
5000 users (and growing), explain in details how will you do it having in mind that each job | |
may take between 4 to 7 minutes to executebut still has to be at one minute interval | |
(there will always be parallel running jobs at any given instance). | |
ANSWER | |
The best way to make the RUN IS TO QUEUE THEM UP AND RUN Asynchronous |
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
<?php | |
namespace Tests\Feature; | |
use Illuminate\Foundation\Testing\RefreshDatabase; | |
use Illuminate\Foundation\Testing\WithFaker; | |
use Tests\TestCase; | |
class EmailValidationTest extends TestCase | |
{ | |
/** | |
* A basic feature test example. | |
* | |
* @return void | |
*/ | |
public function testRequiredFieldsForValidation() | |
{ | |
$this->json('POST', 'api/validate', ['email' => 'horlathunbhosun@gmail.com']) | |
->assertStatus(200) | |
->assertJsonStructure([ | |
"email", | |
"did_you_mean", | |
"user", | |
"domain", | |
"format_valid", | |
"mx_found", | |
"smtp_check", | |
"catch_all", | |
"role", | |
"disposable", | |
"free", | |
"score", | |
]); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment