Posts

Showing posts from May, 2017

Programming Language Tending

对于一个现代人 前端编程语言是这样学的: HTML→JavaScript→由JS引出的各种分支语言 后端编程语言是这样学的: Python→C++→汇编语言→计算机原理以及通用硬件制作与维修 前端后面为趋势,后端前面为趋势。 前者是从现实走进虚拟,后者是从虚拟走进现实。 感觉我是神棍😂

sleep(int) in C++

#include <iostream> #include <time.h> using namespace std; void sleep(unsigned int seconds) {     clock_t goal = seconds*1000000 + clock();     while (goal > clock()); } int main () {     int num=1;     for( ; ; )     {         cout << "This loop will run forever. " << num << endl;         num++;         sleep(1);     }     return 0; }

class __init__() in C++

#include <iostream> using namespace std; class Box {     public:         Box()         {             cout << "You started me.\n";         }               ~Box()         {             cout << "I'm over, now.\n";         } }; int main() {     Box my_box; }

try: except: in C++

#include <iostream> using namespace std; int main() {     try     {         int a, b;         cin >> a >> b;         cout << a / b << endl; //try to divide by 0, you'll see error msg     }     catch(exception &e)     {         cout << "error happend: " << e.what() << endl;     } }

for loop in C++

Just like Python's for loop: #include <iostream> using namespace std; int main () {     int v[] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9};     for (auto x: v)         cout << x << '\n'; }

Find out the biggest number in a int list

#include <iostream> #include <list> #include <iterator> using namespace std; int max(list<int> a_list) {     cout << "You gave me a list with a length of " << a_list.size() << "." << endl;     a_list.sort();     a_list.reverse();     auto iterator = a_list.begin(); //create a iterator     advance(iterator, 0); //give a 0 index, get the expected value in that list     cout << *iterator << " is the biggest in this list." << endl; //from pointer address get int value       return *iterator; } int main () {     //std::list<int> mylist;     //list included in std namespace.     list<int> mylist={2, 3, 4, 1, 0}; //define a list contains int value     max(mylist); //call max function     return 0; }

How to use docker

Normally, you can get all commands by typing:  docker See how many containers you got right now: docker ps -a example `docker run -it --publish 6606:80 --volume ${HOME}/Kivy-Chat:/Kivy-Chat --workdir /Kivy-Chat argensis/python3-kivy:nopip ls` `--publish 6606:80` container 80 part to host 6606 port `-volume ${HOME}/Kivy-Chat:/Kivy-Chat` forwarding Host `${HOME}/Kivy-Chat` to container `Kivy-Chat`  `--workdir /Kivy-Chat` set container workdir to `Kivy-Chat` `argensis/python3-kivy:nopip` image name `ls` just command name, is also could be `python -c "print('hello, docker')"`