Monday, 29 June 2020
How to quickly scan through whole folder and subfolders to find a keyword in all documents?
grep -iRH "keyword"
Wednesday, 24 June 2020
How to enable mandarin or Chinese characters or GBK supported in Ubuntu Sublime?
p/s: copied from https://github.com/seanliang/Codecs33/tree/linux-x64
Installation
Using Package Control to find, install and upgrade Codecs33 is the recommended method to install this plug-in.
Otherwise, you can download this repository as a zip file from one of the branchs (osx, linux-x64, linux-x32) which matchs your platform. Unzip the archive and rename the new folder to Codecs33, then move this folder to Packages folder of Sublime Text (You can find the Packages folder by clicking "Preferences > Browse Packages" menu entry in Sublime Text).
Description (中文说明见README.zh_CN.md)
Due to the limitation of embedded Python with Sublime Text 3, ConvertToUTF8 might not work properly. You can install this plugin to solve the problem.Installation
Using Package Control to find, install and upgrade Codecs33 is the recommended method to install this plug-in.
Otherwise, you can download this repository as a zip file from one of the branchs (osx, linux-x64, linux-x32) which matchs your platform. Unzip the archive and rename the new folder to Codecs33, then move this folder to Packages folder of Sublime Text (You can find the Packages folder by clicking "Preferences > Browse Packages" menu entry in Sublime Text).
Tuesday, 23 June 2020
Zip or Unzip or 7z software in Ubuntu? Use PeaZip
https://www.peazip.org/peazip-portable.html
Saturday, 20 June 2020
Wednesday, 17 June 2020
How to use 7z to zip and unzip with a password?
From http://www.dotnetperls.com:
Note: If the password contains spaces or special characters, then enclose it with single quotes
7z a secure.7z * -pSECRET
Where: 7z : name and path of 7-Zip executable
a : add to archive
secure.7z : name of destination archive
* : add all files from current directory to destination archive
-pSECRET : specify the password "SECRET"
To open :7z x secure.7z
Then provide the SECRET passwordNote: If the password contains spaces or special characters, then enclose it with single quotes
7z a secure.7z * -p"pa$$word @|"
How to use github for source code maintainance?
For own repository maintainance, you can do the following steps:-
1. git clone the github_code_as_root
2. cd root
3. run or modify something in the code
4. cd root
5. git add .
6. git commit "changes have been done"
7. git push
(all code in the master branch of github will be updated)
For collaborated project with others, everything is the same, except:
1.git clone the github_code_as_root
2.cd root
3. git checkout -b ninja_branch
4. git status
5. (modify something, blak blak blak)
6. git add .
7. git commit -m "fix more errors in using scores versus score"
8. git push -u origin ninja_branch
(go to github website and pull a request for merging, add someone to review)
How to remove and create folder at the same time in python?
import os
opath = 'output/images'
if os.path.exists(opath):
shutil.rmtree(opath) # delete output folder
os.makedirs(opath) # make new output folder
opath = 'output/images'
if os.path.exists(opath):
shutil.rmtree(opath) # delete output folder
os.makedirs(opath) # make new output folder
Monday, 15 June 2020
How to fix docker: Got permission denied while trying to connect to the Docker daemon socket
Method1:
- Create the docker group.
sudo groupadd docker
- Add your user to the docker group.
sudo usermod -aG docker ${USER}
- clean the docker cache
rm -rf ~/.docker
- update docker directory right
sudo chmod 666 /var/run/docker.sock
Method2:
You need to do the following:
To create the docker group and add your user:
- Create the docker group.
sudo groupadd docker
- Add your user to the docker group.
sudo usermod -aG docker ${USER}
- You would need to override the docker permission
sudo chmod -R ugo+rw /var/run/docker.sock
sudo systemctl restart docker
sudo reboot / source ~/.bashrc
- Verify that you can run docker commands without sudo.
docker run hello-world
Saturday, 13 June 2020
How to remove a known ip in ssh?
ssh-keygen -f "/home/user/.ssh/known_hosts" -R 192.168.20.123
How to run multi-threading for reading image from camera?
#!/usr/bin/env python
from threading import Thread, Lock
import cv2
class WebcamVideoStream :
def __init__(self, src = 0, width = 640, height = 480, fps = 30) :
self.stream = cv2.VideoCapture(src)
self.stream.set(cv2.CAP_PROP_FRAME_WIDTH, width)
self.stream.set(cv2.CAP_PROP_FRAME_HEIGHT, height)
self.stream.set(cv2.CAP_PROP_FPS, fps)
(self.grabbed, self.frame) = self.stream.read()
self.started = False
self.read_lock = Lock()
def start(self) :
if self.started :
print("already started!!")
return None
self.started = True
self.thread = Thread(target=self.update, args=())
self.thread.start()
return self
def update(self) :
while self.started :
(grabbed, frame) = self.stream.read()
self.read_lock.acquire()
self.grabbed, self.frame = grabbed, frame
self.read_lock.release()
def read(self) :
self.read_lock.acquire()
frame = self.frame.copy()
self.read_lock.release()
return frame
def stop(self) :
self.started = False
self.thread.join()
def __exit__(self, exc_type, exc_value, traceback) :
self.stream.release()
if __name__ == "__main__" :
vs = WebcamVideoStream().start()
while True :
frame = vs.read()
cv2.imshow('webcam', frame)
if cv2.waitKey(1) == 27 :
break
vs.stop()
cv2.destroyAllWindows()
from threading import Thread, Lock
import cv2
class WebcamVideoStream :
def __init__(self, src = 0, width = 640, height = 480, fps = 30) :
self.stream = cv2.VideoCapture(src)
self.stream.set(cv2.CAP_PROP_FRAME_WIDTH, width)
self.stream.set(cv2.CAP_PROP_FRAME_HEIGHT, height)
self.stream.set(cv2.CAP_PROP_FPS, fps)
(self.grabbed, self.frame) = self.stream.read()
self.started = False
self.read_lock = Lock()
def start(self) :
if self.started :
print("already started!!")
return None
self.started = True
self.thread = Thread(target=self.update, args=())
self.thread.start()
return self
def update(self) :
while self.started :
(grabbed, frame) = self.stream.read()
self.read_lock.acquire()
self.grabbed, self.frame = grabbed, frame
self.read_lock.release()
def read(self) :
self.read_lock.acquire()
frame = self.frame.copy()
self.read_lock.release()
return frame
def stop(self) :
self.started = False
self.thread.join()
def __exit__(self, exc_type, exc_value, traceback) :
self.stream.release()
if __name__ == "__main__" :
vs = WebcamVideoStream().start()
while True :
frame = vs.read()
cv2.imshow('webcam', frame)
if cv2.waitKey(1) == 27 :
break
vs.stop()
cv2.destroyAllWindows()
Cutting the videos based on start and end time using ffmpeg
# -ss start point, -to end point
ffmpeg -i input.mp4# -t trim how many seconds from ss
-ss 00:01:00
-to 00:02:00 -c copy output.mp4
ffmpeg -i input.mp4
-t 5 -c copy output.mp4
-ss 00:01:00
This command trims your video in seconds!
I have explained it on my blog here:
-i: This specifies the input file. In that case, it is (input.mp4). -ss: Used with -i, this seeks in the input file (input.mp4) to position. 00:01:00: This is the time your trimmed video will start with. -to: This specifies duration from start (00:01:40) to end (00:02:12).The timing format is: hh:mm:ss
00:02:00: This is the time your trimmed video will end with. -c copy: This is an option to trim via stream copy. (NB: Very fast)
p/s: https://stackoverflow.com/questions/18444194/cutting-the-videos-based-on-start-and-end-time-using-ffmpeg
Monday, 8 June 2020
How to Use Mandarin / Pinyin / Chinese in Ubuntu?
- Go to System Settings–> Language Support–> Install/Remove Languages, select Chinese(Simplified)
- Open the terminal and install the IBus framework with following command:
sudo apt-get install ibus ibus-clutter ibus-gtk ibus-gtk3 ibus-qt4
- Start the IBus framework. In terminal input:
im-config -s ibus
- Install the Pinyin engine
sudo apt-get install ibus-pinyin
- Restart IBus daemon
ibus restart
- Setting the IBus
ibus-setup
In the popup window, switch to Input Method tab,click the Add button to choose the Chinese input method installed just now. - Go to the Text Entry (from the right-top corner of the window or from the System Settings -> Text Entry) for the shortcut of input method exchange.
- Select Intelligent Pinyin
Saturday, 6 June 2020
How to delete multiple lines in vim?
1. Press
2. Move the cursor to the first line you want to remove.
3. Use one of the following commands (replacing
Esc
.2. Move the cursor to the first line you want to remove.
3. Use one of the following commands (replacing
[#]
with the number of lines):[#]dd
Wednesday, 3 June 2020
How to get the file base name from a path using python?
>>> import os
>>> base=os.path.basename('/root/dir/sub/file.ext')
>>> base
'file.ext'
Subscribe to:
Posts (Atom)