seymaster / hng_storm-task Goto Github PK
View Code? Open in Web Editor NEWtask answer
task answer
Awesome work I've seen on the repo. I noticed the code for individual scripts in the scripts folder returns JSON as well as the string. I think since the instructions said the individual scripts should return strings alone, we should stick to that. Here's some code I've ran and tested that works well on my system for js, php, dart and python.
<?php
$log_directory = dirname(__FILE__);
// $files = [];
$path = $log_directory . '\scripts\*.*';
$output = array();
$res = array();
$fullnameRegex = "/\sis\s(.*)\swith/";
$idRegex = "/\sID\s(.*)\susing/";
$languageRegex = "/\susing\s(.*)\sfor/";
foreach (glob($path) as $key => $file) {
$new = array();
if (pathinfo($file)['extension'] == 'js') {
exec("node $file", $output);
} else if (pathinfo($file)['extension'] == 'py') {
exec("python $file", $output);
} else if (pathinfo($file)['extension'] == 'dart') {
exec("dart $file", $output);
} else if (pathinfo($file)['extension'] == 'php') {
exec("php $file", $output);
}
if (preg_match("$fullnameRegex", $output[$key], $matches1)) {
$new['full name'] = $matches1[1];
}
if (preg_match("$idRegex", $output[$key], $matches1)) {
$new['ID'] = $matches1[1];
}
if (preg_match("$languageRegex", $output[$key], $matches1)) {
$new['language'] = $matches1[1];
}
array_push($res, $new);
}
var_dump(json_encode($res, true));
The final result is:
string(256) "[{"full name":"[full dart]","ID":"[ID]","language":"[language]"},{"full name":"[full
js]","ID":"[ID]","language":"[language]"},{"full name":"[full php]","ID":"[ID]","language":"[language]"},{"full
name":"[full python]","ID":"[ID]","language":"[language]"}]"
We are supposed to set our working branch as the default branch, so that all PRs will be made to it. It is not good for PRs to be made to the master branch. I can see that many people are making their PRs to the master branch.
status could be part of the final json response for each member
Please can the repo maintainers write a readme telling us what exactly our script is expected to console.log or print, either JSON or string.
Also we need to know in the readme, the branch that we are to push to. This will make things very easy for everybody. Thanks.
We need to store the results down in a json file that will be loaded in index.php mapping files to results. Only files that are not in that json file will be 'exec'ed. Reason: I am using a phone to load the page. With just 6 scripts, it takes up to a 30 seconds to load. Let us say, a computer is 10 times faster ie 6 scripts in 3 seconds. If half of the team submits: 300 scripts. 300/6 * 3 = 150 seconds. One minute and 30 seconds. On some browsers, that classifies as a timeout. Think of it.
On the thread, it was said square brackets should not be part of output but index.php still checks for it.
Notice: Undefined variable: filename in /Users/ambrose/Dev/hngi7/HNG_storm-task/index.php on line 90
Notice: Undefined index: QUERY_STRING in /Users/ambrose/Dev/hngi7/HNG_storm-task/index.php on line 94
error_reporting(E_ERROR | E_PARSE);
The following error appears on the header of the index page.
Notice: Undefined variable: filename in /Users/ambrose/Dev/hngi7/HNG_storm-task/index.php on line 90
Notice: Undefined index: QUERY_STRING in /Users/ambrose/Dev/hngi7/HNG_storm-task/index.php on line 94
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.