Skip to content

Instantly share code, notes, and snippets.

@QinMing
QinMing / reset_line_ending.py
Last active December 14, 2020 04:06
Set the correct line ending, either CRLF or LF, for a directory tree
#!/usr/bin/env python3
#
# Sample Usage:
# <command> '.*\.html'
import logging
import os
import re
from argparse import ArgumentParser
@QinMing
QinMing / .zshrc
Last active January 4, 2022 19:38
my very own zshrc
# Copyright (c) 2016-2021 Ming Qin (覃明) <https://github.com/QinMing>
# Open source under MIT LICENSE.
export PATH=/usr/local/bin:$PATH
export ZSH="$HOME/.oh-my-zsh"
DISABLE_MAGIC_FUNCTIONS=true
# So that it doesn't add the extra excape character. Without this line, pasting `mingq.in/?param` will become `mingq.in/\?param`
ZSH_THEME="agnoster"
@QinMing
QinMing / makefile
Last active October 9, 2018 08:26
MySQL utils
backup:
docker stop mysql1 || true
docker run --rm --volumes-from mysql1 -v $(BACK_DIR):/backup ubuntu tar cvf /backup/sql_volume.tar /var/lib/mysql
docker start mysql1
restore:
docker stop mysql1
docker run --rm --volumes-from mysql1 -v $(BACK_DIR):/backup ubuntu bash -c "rm -rf /var/lib/mysql/* && cd / && tar xvf /backup/sql_volume.tar"
docker start mysql1
load:
docker exec -i mysql1 mysql -uroot $(DATABASE_NAME) < mysqldump
@QinMing
QinMing / schemaspy.sh
Created July 26, 2018 18:14
Run schemaspy
docker run -it --rm --net=host -v $PWD/static:/data mnuessler/schemaspy -hq -t mysql \
-host YOUR-DB.COM \
-u USER \
-p 'PASSWORD' \
-db DB_NAME \
-o /data/FOLDER_NAME
@QinMing
QinMing / dotfile.sh
Last active November 7, 2017 09:26
Dot file
#!/bin/bash
# To run this file itself:
# wget https://gist.githubusercontent.com/QinMing/48cfe1e0a5b65d4c62dc2da8b91ab145/raw -O dotfile.sh && chmod +x dotfile.sh
shell=bash
# Print out message in color
success() {
echo -e "\033[1;32m$1\033[0m"
alias grep='grep --color=auto'
alias l="ls -alhtr"
alias g='git'
alias gs="git status"
alias gl="git l"
alias gd="git diff"
alias gb="git branch"
alias gp="git pull"
function parse_git_branch() {
du -hs *
eval "echo \"$(< $STARTUP_TPL_PATH)\"" > $STARTUP_PATH
chmod +x $STARTUP_PATH
@QinMing
QinMing / .zshrc
Last active March 10, 2024 22:17
.zshrc (lazy loading shell functions)
# Copyright (c) 2016-2018 Ming Qin (覃明) <https://github.com/QinMing>
# Open source under MIT LICENSE.
lazy_load() {
# Act as a stub to another shell function/command. When first run, it will load the actual function/command then execute it.
# E.g. This made my zsh load 0.8 seconds faster by loading `nvm` when "nvm", "npm" or "node" is used for the first time
# $1: space separated list of alias to release after the first load
# $2: file to source
# $3: name of the command to run after it's loaded
# $4+: argv to be passed to $3
@QinMing
QinMing / ss
Last active May 27, 2020 17:29
upload/download current folder to the same position at remote host
#!/bin/bash
#
# Copyright (c) 2016 Ming Qin (覃明) <https://github.com/QinMing>
# Open source under MIT LICENSE.
# Notice:
# dot files in remote will not be downloaded since we are using `zip -r -q ~/$ZIP_FILE_NAME ./*`
# This is to protect local dot files
# Change this to `zip blabala . ` if dot files are wanted. Also, `find . -delete` need to change
# Note: `find $path -delete` will delete the folder itself, so use `find . -delete`