Welcome to Yi Hsiao’s notes!¶
git¶
Resources¶
- Basic:
- Advanced
- git hook
- git reflog
- ORIG_HEAD
- Others
- learn interactively learngitbranching.js
Python¶
FAQ¶
- How do I check whether a file exists using Python?
- Does Python have a ternary conditional operator?
- How to check if a directory exists and create it if necessary?
- What does if __name__ == “__main__”: do?
- Calling an external command in Python
- Python join: why is it string.join(list) instead of list.join(string)?
- How can I remove (chomp) a newline in Python?
- rstrip(”\n”)
- Universal line break
- What is the purpose of self?
- How can I print all arguments passed to a python script?
- Delete an item from a dictionary
- Differnece between __repr__ and __str__
Shell script¶
Cheatsheet¶
get current directory of the script that is performed
DIR="$( cd "$( dirname "$0" )" && pwd )"
rsync
rsync -avzh /mypath/myfile.gz pi@192.168.1.12:/mybackup/
AWS (Linux)¶
Add a user¶
sudo adduser [user name]
sudo password [user name]
Steps to expand EBS disk size¶
Modify the size in the Volume page
sudo yum install xfsprogs
[ec2-user ~]$ lsblk NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT xvda 202:0 0 30G 0 disk └─xvda1 202:1 0 30G 0 part / xvdb 202:16 0 30G 0 disk /mnt xvdf 202:80 0 35G 0 disk └─xvdf1 202:81 0 8G 0 part [ec2-user ~]$ df -h Filesystem Size Used Avail Use% Mounted on /dev/xvda1 8.0G 943M 6.9G 12% / tmpfs 1.9G 0 1.9G 0% /dev/shm /dev/xvdf 1014M 33M 982M 4% /mnt [ec2-user ~]$sudo growpart /dev/xvdf 1 CHANGED: disk=/dev/xvdf partition=1: start=4096 old: size=16773086,end=16777182 new: size=73396190,end=73400286 [ec2-user ~]$ sudo xfs_growfs -d /mnt meta-data=/dev/xvdf isize=256 agcount=4, agsize=65536 blks = sectsz=512 attr=2 data = bsize=4096 blocks=262144, imaxpct=25 = sunit=0 swidth=0 blks naming =version 2 bsize=4096 ascii-ci=0 log =internal bsize=4096 blocks=2560, version=2 = sectsz=512 sunit=0 blks, lazy-count=1 realtime =none extsz=4096 blocks=0, rtextents=0 data blocks changed from 262144 to 26214400
Docker¶
FAQ¶
Enter detached container (for example, a development server)
docker run -d -p 8888:8888 python:3.5 python -m http.server 8888 --name python_http docker exec -it python_http /bin/bash
Mount the data to the container
docker run -ti -v "$PWD":/work_dir ubuntu:14.04 /bin/bash
Remove the
images docker images -f "dangling=true" -q
Rename the image
docker tag <old_name> <new_name> docker rmi <old_name>