Commit d980982a by songxinkai

20181224, add sshpass, boost_fs examples.

parent 65052b86
// g++ test0.cpp -I /usr/include/filesystem -L /usr/lib/x86_64-linux-gnu/ -lboost_filesystem -lboost_system
#include <unistd.h>
#include <iostream>
#include <vector>
#include <string>
#include <boost/filesystem.hpp>
namespace fs = boost::filesystem;
using namespace std;
int main (){
fs::path path("data/go");
cout << path << endl;
cout << path.has_filename() << endl;
cout << path.filename() << endl;
path /= "1.bin";
cout << path << endl;
cout << path.has_filename() << endl;
cout << path.filename() << endl;
cout << system_complete(path) << endl; //
cout << path.is_absolute() << endl;
cout << path.extension() << endl;
cout << path.root_path() << endl;
cout << path.root_name() << endl;
cout << path.relative_path() << endl;
cout << path.root_directory() << endl;
path = system_complete(path);
cout << path.is_absolute() << endl;
char file_name[] = "b";
if ( 0 == access(file_name, 0) ) cout<<"access(): path exist."<<endl;
return 0;
}
int get_filenames(const std::string& dir, std::vector<std::string>& filenames)
{
fs::path path(dir);
if (!fs::exists(path)){
return -1;
}
fs::directory_iterator end_iter;
for (fs::directory_iterator iter(path); iter!=end_iter; ++iter){
if (fs::is_regular_file(iter->status())){
filenames.push_back(iter->path().string());
}
if (fs::is_directory(iter->status())){
get_filenames(iter->path().string(), filenames);
}
}
return filenames.size();
}
......@@ -5,6 +5,8 @@ namespace fs = boost::filesystem;
using namespace std;
int main(){
fs::path path("data/go/1.bin");
cout << path.filename() << endl;
cout << fs::exists("a") << endl;
cout << fs::exists("b") << endl;
cout << fs::is_directory("b") << endl;
......
// g++ main.cpp -std=c++11
#include <iostream>
#include <vector>
#include <string>
#include <fstream>
using namespace std;
void read(const string file, vector<vector<float> >& feas,
vector<vector<float> >& pis, vector<float>& vs){
int steps_in = 0;
float winner_in = 0.0;
char feas_in[1000 * 17*19*19];
float pis_in[1000 * 362];
std::ifstream input(file, ios::in | ios::binary);
input.read((char*)&steps_in, sizeof(int));
// CHECK_LE(steps_in, 1000);
input.read((char*)&winner_in, sizeof(float));
input.read((char*)feas_in, sizeof(char) * 19*19*17 * steps_in);
input.read((char*)pis_in, sizeof(float) * (19*19+1) * steps_in);
input.close();
feas.resize(steps_in);
pis.resize(steps_in);
vs.resize(steps_in);
for (int step = 0; step < steps_in; ++step){
feas[step].resize(17*19*19);
pis[step].resize(1+19*19);
for (int j = 0; j < 17*19*19; ++j){
feas[step][j] = feas_in[step*17*19*19 + j] ? 1.0 : 0.0;
}
for (int j = 0; j < 1+19*19; ++j){
pis[step][j] = pis_in[step*(1+19*19)+j];
}
if ((step%2==0)^(winner_in==1.0)){ // self lose
vs[step] = -1.0;
}else{
vs[step] = 1.0;
}
}
}
void write(const string file){
int steps_out = 400;
float winner_out = 1.0;
unsigned char feas_out[1000 * 17*19*19];
float pis_out[1000 * 362];
for (int i = 0; i < steps_out; ++i){
for (int j = 0; j < 19*19; ++j){
for (int c = 0; c < 17; ++c){
feas_out[i*17*19*19+j*17+c] = (c == i%17 && j <= i%361) ? (unsigned char)1 : (unsigned char)0;
}
}
for (int j = 0; j < 362; ++j){
pis_out[i * 362 + j] = float(i + j * 0.001);
}
}
std::ofstream output(file, ios::out | ios::binary );
output.write((char*)&steps_out, sizeof(int));
// CHECK_LE(steps_out, 1000);
output.write((char*)&winner_out, sizeof(float));
output.write((char*)feas_out, sizeof(char) * 19*19*17*steps_out);
output.write((char*)pis_out, sizeof(float) * (19*19+1) * steps_out);
output.close();
}
int main (){
write("test.bin");
vector<vector<float> > feas;
vector<vector<float> > pis;
vector<float> vs;
read("test.bin", feas, pis, vs);
cout << feas.size() << ", " << pis.size() << ", " << vs.size() << ", " << endl;
for (int i = 0; i < feas.size(); ++i){
cout << "========" << i << "======" << endl;
for (int j = 0; j < 19*19; ++j){
for (int c = 0; c < 17; ++c){
cout << feas[i][j*17+c] << ", ";
}
cout << endl;
}
for (int j = 0; j < pis[i].size(); ++j){
cout << pis[i][j] << ", ";
}
cout << endl << vs[i] << endl;
}
return 0;
}
No preview for this file type
......@@ -12,4 +12,5 @@ int main()
printf("%d ",j);
}
printf("\n");
return 0;
}
// g++ random.cpp -std=c++11
#include <random>
#include <iostream>
......
No preview for this file type
#include <stdlib.h>
#include <iostream>
#include <unistd.h>
......@@ -6,9 +5,9 @@ using namespace std;
int main(){
for (int i = 0; i < 10; ++i){
sleep(2);
sleep(1);
cout << "1" << endl;
usleep(2000000);
usleep(500000);
cout << "2" << endl;
}
return 0;
......
No preview for this file type
#include <string>
#include <algorithm>
#include <vector>
#include <iostream>
using namespace std;
int main(){
string a("aaaaassfaaaaa ff ");
string b("ccc");
string c("ff");
string a("1.bin.finish");
string b(".finish");
string c("1.bin");
vector<string> v;
v.push_back(a);
v.push_back(b);
v.push_back(c);
cout << string::npos << endl;
cout << a.find(b) << endl;
cout << a.find(c) << endl;
cout << a.find("f") << endl;
if (string::npos != a.find(b)){
cout << a << " find " << b << ", at " << a.find(b) << endl;
cout << a.substr(0, a.find(b)) << " + " << b << " = " << a << endl;
}
vector<string>::iterator it_str = find(v.begin(), v.end(), c);
cout << (it_str == v.end()) << ", " << *it_str << endl;
return 0;
}
No preview for this file type
File added
......@@ -8,7 +8,6 @@ using namespace std;
int main(){
stringstream ss;
string s = "c.";
system("nvidia-smi");
system(("touch " + s + "out").c_str());
ss << "mv " << "c.out " << "b.out";
system(ss.str().c_str());
......
#include <stdlib.h>
#include <iostream>
#include <sstream>
#include <string>
using namespace std;
int main(){
system("sshpass -p \"sxk123\" scp -o StrictHostKeyChecking=no root@47.94.192.213:/root/b.exe .");
return 0;
}
File added
#include <iostream>
#include <vector>
using namespace std;
int main(){
vector<int> a(5,1);
cout << a.size() << endl;
a.erase(a.begin()+2);
cout << a.size() << endl;
a.pop_back();
cout << a.size() << endl;
return 0;
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment