JSON_HEX_APOS
as the second parameter which will convert all single quotes '
to \u0027
. :
var t = <?php echo json_encode($data, JSON_HEX_APOS);?>;
Then use encode ()
and decode ()
javascript functions to convert the text from each array entry back to readable text like this examplewindow.location.hash: "#2"
window.location.host: "localhost:4200"
window.location.hostname: "localhost"
window.location.href: "http://localhost:4200/landing?query=1#2"
window.location.origin: "http://localhost:4200"
window.location.pathname: "/landing"
window.location.port: "4200"
window.location.protocol: "http:"
window.location.search: "?query=1"
bash /root/path/scripts/laravel_path_permissions.sh
set -e
set -x
# DETERMINE THE PROJECT BASE PATH ASSUMING THIS SCRIPT WAS
# STORED WITHIN THE /project_root_directory/scripts
BASE_PATH="$(dirname -- $(cd -P -- "$(dirname -- "$0")" && pwd -P))"
LOG_FILE="$BASE_PATH/storage/logs/laravel.log"
if [ ! -f ${LOG_FILE} ]; then
echo "CREATING LOG FILE: storage/logs/laravel.log "
touch ${LOG_FILE}
echo "SETTING LOG FILE PERMISSIONS:"
sudo chmod 665 ${LOG_FILE}
sudo chown $USER:www-data ${LOG_FILE}
echo "SETTING LOG FILE PERMISSIONS OK!"
else
echo "LOG_FILE ALREADY SETUP!"
fi
if [[ ! -d $BASE_PATH/vendor && -d $BASE_PATH/bootstrap && -d $BASE_PATH/storage ]]; then
echo "DEFINE THE WRITABLE AND EXECUTABLE PERMISSION FOR THE WEBSERVER OWNER AND GROUP ..."
sudo chmod 775 $BASE_PATH/bootstrap/cache
sudo chmod 775 $BASE_PATH/storage/framework/cache
sudo chmod 775 $BASE_PATH/storage/framework/cache/data
sudo chmod 775 $BASE_PATH/storage/framework/sessions
sudo chmod 775 $BASE_PATH/storage/framework/views
sudo chmod 775 $BASE_PATH/storage/logs
echo "CHANGE THE PERMISSIONS GROUP FOR THE WEBSERVER USER ..."
sudo chgrp www-data $BASE_PATH/bootstrap/cache
sudo chgrp www-data $BASE_PATH/storage/framework/cache
sudo chgrp www-data $BASE_PATH/storage/framework/cache/data
sudo chgrp www-data $BASE_PATH/storage/framework/sessions
sudo chgrp $USER $BASE_PATH/storage/framework/views
sudo chgrp www-data $BASE_PATH/storage/logs
echo "PERMISSIONS DONE!"
else
echo "PERMISSIONS ALREADY SETUP!"
fi
composer require symfony/process
-----------------analyse_string.py---------------------
# analyse_string.py
#!/usr/bin/python
import sys
from vaderSentiment.vaderSentiment import SentimentIntensityAnalyzer
analyser = SentimentIntensityAnalyzer()
print(str(analyser.polarity_scores(sys.argv[1])))
-------------------------- Laravel Code---------------------------
use Symfony\Component\Process\Process;
use Symfony\Component\Process\Exception\ProcessFailedException;
$text = 'The text you are desperate to analyze :)";
$process = new Process("python3 /Path/To/analyse_string.py \"{$text}\"");
$process->run();
// executes after the command finishes
if (!$process->isSuccessful()) {
throw new ProcessFailedException($process);
}
echo $process->getOutput();
// Result (string): {'neg': 0.204, 'neu': 0.531, 'pos': 0.265, 'compound': 0.1779}
You can also pass array to python using json string
$process = new Process("python3 /Path/To/analyse_json.py {$json}");
and inside python retrieve it like this
x=sys.argv[1]
data=json.loads(x)
for item in data:
#do whatever u want
$context = stream_context_create(
array(
"http" => array(
"header" => "User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/50.0.2661.102 Safari/537.36"
)
)
);
echo file_get_contents("www.google.com", false, $context);
function shallowClone(obj) {
var clone = Object.create(Object.getPrototypeOf(obj));
var props = Object.getOwnPropertyNames(obj);
props.forEach(function(key) {
var desc = Object.getOwnPropertyDescriptor(obj, key);
Object.defineProperty(clone, key, desc);
});
return clone;
}
In ES2017function shallowClone(obj) {
return Object.create(
Object.getPrototypeOf(obj),
Object.getOwnPropertyDescriptors(obj)
);
}
var hidden, visibilityState, visibilityChange;
if (typeof document.hidden !== "undefined") {
hidden = "hidden", visibilityChange = "visibilitychange", visibilityState = "visibilityState";
}
else if (typeof document.mozHidden !== "undefined") {
hidden = "mozHidden", visibilityChange = "mozvisibilitychange", visibilityState = "mozVisibilityState";
}
else if (typeof document.msHidden !== "undefined") {
hidden = "msHidden", visibilityChange = "msvisibilitychange", visibilityState = "msVisibilityState";
}
else if (typeof document.webkitHidden !== "undefined") {
hidden = "webkitHidden", visibilityChange = "webkitvisibilitychange", visibilityState = "webkitVisibilityState";
}
document.addEventListener(visibilityChange, function(event){
switch (document[visibilityState]) {
case "visible":
// tab is focused
break;
case "hidden":
// tab is blurred
break;
}
});