Skip to content

Instantly share code, notes, and snippets.

Avatar

Doni Leong donilan

View GitHub Profile
@donilan
donilan / docker_cleanup.sh
Last active May 20, 2020
Clean docker by cronjob
View docker_cleanup.sh
#!/usr/bin/env bash
#write out current crontab
crontab -l > /tmp/mycron
cat << EOF >> /tmp/mycron
# please pay atention, 168h is 7 days, which mean is it only keep the images created in 14 days, other will be removed.
0 0 * * * docker image prune -a --filter "until=$(date +'%Y-%m-%dT%H:%M:%S' --date='-14 days')"
5 0 * * * docker container prune -f
10 0 * * * docker volume prune -f
@donilan
donilan / backup_mysql.sh
Created May 14, 2020
dump/backup mysql database in docker way
View backup_mysql.sh
#!/usr/bin/env bash
docker run --rm mysql:5.7 mysqldump \
-uUSERNAME \
-hmysq.example.com \
-pPASSWORD database_name | gzip > /path/to/your/backup/folder/backup_$(date +"%Y%m%d_%H%M%S").sql.gz
# only keep 5 backups
ls -1tr | head -n -5 | xargs -d '\n' rm -f --
@donilan
donilan / configure_cloudwatch_for_docker.sh
Last active May 14, 2020
Configure CloudWatch for docker on ubuntu
View configure_cloudwatch_for_docker.sh
#!/usr/bin/env bash
cat << EOF | sudo tee /etc/systemd/system/docker.service.d/aws-credentials.conf
[Service]
Environment="AWS_ACCESS_KEY_ID=$AWS_ACCESS_KEY_ID"
Environment="AWS_SECRET_ACCESS_KEY=$AWS_SECRET_ACCESS_KEY"
EOF
sudo systemctl daemon-reload
sudo systemctl start docker
@donilan
donilan / docker-compose-with-redmine.yml
Created May 14, 2020
docker-compose.yml for redmine
View docker-compose-with-redmine.yml
version: '3'
services:
reverse-proxy:
image: traefik:v2.2
restart: always
command:
# - "--log.level=DEBUG"
- "--api.insecure=true"
- "--providers.docker=true"
- "--providers.docker.exposedbydefault=false"
@donilan
donilan / create_swap.sh
Created Apr 24, 2020
Create swap for centos
View create_swap.sh
#!/usr/bin/env
sudo dd if=/dev/zero of=/swapfile bs=4096 count=1024k && \
sudo chmod 600 /swapfile && \
sudo mkswap /swapfile && \
sudo swapon /swapfile && \
sudo cp /etc/fstab{,.bak} && \
sudo echo "/swapfile swap swap sw 0 0" | \
sudo tee -a /etc/fstab
@donilan
donilan / update_hostname.sh
Last active May 11, 2020
Update hostname, before execute this script, please export NEW_HOSTNAME=your.new.domain
View update_hostname.sh
#!/usr/bin/env bash
sudo hostname $NEW_HOSTNAME
hostname | sudo tee /etc/hostname
sudo sed -i -e "s/ $(hostname)//g" -e "/127.0.0.1/s/\$/ $(hostname)/" /etc/hosts
@donilan
donilan / install_docker_ce.sh
Last active May 11, 2020
Install docker ce on centos7
View install_docker_ce.sh
#!/usr/bin/env bash
sudo yum install -y yum-utils \
device-mapper-persistent-data \
lvm2
sudo yum-config-manager \
--add-repo \
https://download.docker.com/linux/centos/docker-ce.repo
sudo yum makecache fast
@donilan
donilan / init_emacs.sh
Created Apr 22, 2020
init emacs, no tail file
View init_emacs.sh
cat <<EOF > ~/.emacs
(custom-set-variables
'(auto-save-default nil)
'(create-lockfiles nil)
'(make-backup-files nil))
EOF
View keybase.md

Keybase proof

I hereby claim:

  • I am donilan on github.
  • I am doni (https://keybase.io/doni) on keybase.
  • I have a public key ASCDRtxIq0fso6gX8bwx8HEMtdTjiruO7MGIuDsCURS5Ygo

To claim this, I am signing this object:

@donilan
donilan / osx_copy_paste_with_chinese.el
Created Jul 31, 2017
Copy/paste with system clipboard, support Chinese or other unicode.
View osx_copy_paste_with_chinese.el
(defun copy-from-osx ()
(shell-command-to-string "pbpaste"))
(defun paste-to-osx (text &optional push)
(let ((process-connection-type nil)
(lang (getenv "LANG"))
(default-directory "~"))
(setenv "LANG" "en_US.UTF-8")
(let ((proc (start-process "pbcopy" "*Messages*" "pbcopy")))
(process-send-string proc text)
You can’t perform that action at this time.