การจับเวลาด้วย Python

ตัวอย่างการใช้ฟังก์ชั่น clock() and time() บน Windows and Linux
Run on linux
  >>> from time import clock, time
  >>> print clock(), time()
  0.01 1169573460.96
  >>> print clock(), time()
  0.01 1169573463.76
  >>> print clock(), time()
  0.01 1169573467.09
  >>> 

QueryPerformanceCounter()

ฟังก์ชั่น QueryPerformanceCounter() ใช้จับเวลาการทำงาน เป็นฟังก์ชั่นที่มีใน Windows ส่วนใน Linux ต้องเขียนฟังก์ชั่นนี้เอง โดย Code แสดงดังข้างล่างนี้
This function basically recreates the win32 QueryPerformanceCounter() on Linux, play with this code:

Time command

$ time ls
real    0m0.005s
user    0m0.004s
sys    0m0.000s

        * The elapsed (real) time between invocation of utility and its
termination.

* The User CPU time, equivalent to the sum of the tms_utime and
tms_cutime fields returned by the times() function defined in the
System Interfaces volume of IEEE Std 1003.1-2001 for the process in
which utility is executed.

Installing OpenCV on Linux (Ubuntu)

ทดสอบบน Ubuntu 10.04 LTS (Lucid Lynx)

1. ก่อนอื่นติดตั้ง package ที่จำเป็นดังนี้

g++, libgtk2.0-dev

2. จากนั้นทำการติดตั้ง package ดังต่อไปนี้

libcv4
libcv-dev
libcvaux4
libcvaux-dev
libhighgui4
libhighgui-dev
opencv-doc
(‘python-opencv’ not required)

3. จากนั้นทดลองทำการบันทึกไฟล์ hello.cpp ไว้ทดสอบ

 

แสดงเวลาว่าเครื่องเปิดมานานเท่าไหร่แล้ว (เฉพาะ Linux) ด้วย Python

แสดงเวลาว่าเครื่องเปิดมานานเท่าไหร่แล้ว (เฉพาะ Linux) ด้วย Python
การดูว่าเครื่องเปิดมานานเท่าไหร่แล้วบน Linux ปกติใช้คำสั่ง uptime แต่ถ้าต้องการเขียน script เพื่อรายงานเวลาว่าเครื่องเปิดมานานเท่าไหร่แล้ว สามารถใช้ Python เขียน Code ได้ดังนี้

IIS start ไม่ได้ ด้วย Error ดังนี้ unexpected error 0x8ffe2740 occurred

อาการ: IIS start ไม่ได้ ด้วย Error ดังนี้ unexpected error 0x8ffe2740 occurred
สาเหตุ: เกิดจาก port ชนกัน
วิธีแก้ไข: ให้ไปเปลี่ยน port ของ IIS เช่นเปลี่ยนเป็น port 81
ที่มา: "Unexpected Error 0x8ffe2740 Occurred" Error Message When You Try to Start a Web Site

Backing up and restoring MySQL databases

ไฟล์ข้อมูลของ MySQL เก็บไว้ที่ /var/lib/mysql
ส่วนการ Backing up and restoring MySQL databases ดูได้ที่นี่

Basic Commands

คำสั่งต่างๆที่จำเป็น เช่น
df -h ดูการใช้พื้นที่ Harddisk
du -sh folder_name ดูการใช้พื้นที่ของแต่ละ folder
 
ที่มา: UsingTheTerminal, Basic Commands

Syndicate content