#include <iostream>
#include <map>
#include <sstream>
#include <string>
#include <vector>
std::string GetFieldId(std::string sentenceId, int fieldIndex)
{
// Combine the sentence ID and field index to create the field ID
std::ostringstream oss;
oss << sentenceId << "-" << fieldIndex;
return oss.str();
}
std::vector<std::string> SplitString(std::string str, char delimiter)
{
std::vector<std::string> parts;
std::stringstream ss(str);
std::string part;
while (std::getline(ss, part, delimiter)) {
parts.push_back(part);
}
return parts;
}
std::map<std::string, std::string> ParseNmeaString(std::string nmeaString)
{
std::map<std::string, std::string> components;
if (nmeaString.length() < 7 || nmeaString[0] != '$' || nmeaString[nmeaString.length()-3] != '*') {
return components;
}
std::string sentence = nmeaString.substr(1, nmeaString.length()-4);
std::string checksum = nmeaString.substr(nmeaString.length()-2, 2);
std::vector<std::string> parts = SplitString(sentence, ',');
std::string sentenceId = parts[0];
for (int i = 1; i < parts.size(); i++) {
components[GetFieldId(sentenceId, i)] = parts[i];
}
return components;
}
int main()
{
std::string sentence = "$GPGGA,092750.000,5321.6802,N,00630.3372,W,1,8,1.03,61.7,M,55.2,M,,*76";
std::map<std::string, std::string> components = ParseNmeaString(sentence);
// Print the components to the console
for (auto const& component : components) {
std::cout << component.first << ": " << component.second << std::endl;
}
return 0;
}
Simple NMEA Parsing
C/C++ Programming Posted on 05 Apr, 2023 13:39:58- Comments(0) https://www.guivi.one/?p=228
- Share
How do I give www-data user to a folder in my home folder?
Web Development Posted on 05 Apr, 2023 13:37:23First, add yourself into the group www-data
usermod -a -G www-data (your username)
Then:
chgrp www-data /home/myuser/folderA
chmod g+rwxs /home/myuser/folderA
Should do the trick unless the permissions on your /home/myuser
do not permit other users access.
The first command changes the group ownership of the folder to that of the webserver. The second command gives members of the www-data
group read, write, enter-directory rights, and the group s
flag will ensure that any files that get created inside that directory take www-data
as the group – so if you create a file as myuser
the www-data
user will have access.
Nb. this also depends on the umask
settings of both your user account and the webserver: you need to make sure that files created in folderA have group rw
access (and directories created within need group rwx
)
If your webserver does not have enter rights into your /home/myuser
dir (quite sensible) then it’s not going to get in there unless you do something else. Two solns:
sudo mount --bind /home/myuser/folderA /var/www/mysite/folderA
(this is an ugly hack and would have to be repeated after reboot. But a powerful trick, also can be used to make folders accessible inside SSH jails.)- Simply move the shared folder somewhere else, e.g.
/home/shared-stuff/folderA
.
The 2nd option is nicest. Let’s say the stuff in folderA is really public and you don’t care who sees it, you can set it up like
sudo mkdir -m777 /home/shared-stuff
Then you can put inside that, say, folderA with permissions as above, and folderB that www-data should not have access to with different permissions, e.g.
$ cd /home/shared-stuff ; ls -l
drwxrwsr-x 2 myuser www-data 4096 Jan 17 21:46 folderA
drwxrwx--- 2 myuser myuser 4096 Jan 17 21:46 folderB
Source: https://askubuntu.com/a/244410/957246
- Comments(0) https://www.guivi.one/?p=225
- Share