Listing posts

Displaying posts 6 - 10 of 234 in total
gitconfig global file and tools
mouse 786 · person cloud · link
Last update
2020-06-14
2020
06-14
« — »
  • Setup a main config file in /etc/gitconfig or ~/.gitconfig:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
[alias]
  co = checkout
  ci = commit
  st = status
  br = branch
  df = diff --staged
  cp = cherry-pick
  bd  = branch --edit-description
  bds = !GIT_EDITOR=cat git branch --edit-description | grep -v "^#"
  pom = push origin master
  lom = pull origin master
  poa = push origin alb
  loa = pull origin alb
  lst = ls-tree --full-tree -r HEAD
  hist = log --pretty=format:\"%h %ad | %s%d [%an]\" --date=short
  histg = log --pretty=format:\"%h %ad | %s%d [%an]\" --graph --date=short
  undoci = reset --soft HEAD^
  redoci = commit -c ORIG_HEAD
  stash-unapply = !git stash show -p | git apply -R
  stash-diff = stash show -p
  ; drop all local commits and align with origin/master
  reset-om = reset --hard origin/master
  ; side-by-side diff commands (install ydiff command)
  dfs   = !git diff  --staged | ydiff -s -w 0 -t 2 --wrap
  diffs = !git diff           | ydiff -s -w 0 -t 2 --wrap

[user]
  name  = Alberto Cavalin
  email = acavalin@users.noreply.github.com

[credential "https://github.com"]
  username = acavalin

[core]
  autocrlf = input
  safecrlf = true
  editor = nano
  excludesfile = ~/.gitignore_global

[push]
  default = current

[color]
  ui = true
  • Enable adding CR/LF files
1
2
git config --global core.autocrlf false
git config --global core.safecrlf false

resulting in this ~/.gitconfig:

1
2
3
[core]
  autocrlf = false
  safecrlf = false
  • Setup the ignore list in ~/.gitignore_global:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
# jEdit temporary files
*.marks
\#Untitled-*#

# Rails files (db, log, temp, cfg)
/db/*.sqlite3
/db/*.sqlite3-journal
/log/*.log
/log/*.gz
/tmp
Gemfile.lock
/config/database.yml

.DS_Store
nohup.out
  • Use a side-by-side colored diff tool

  • Enhance the terminal experience:

    1
    2
    3
    [ -f "$HOME/.git-completion.bash" ] && source "$HOME/.git-completion.bash"
    [ -f "$HOME/.git-prompt.sh" ] && source "$HOME/.git-prompt.sh"
    export PROMPT_COMMAND='__git_ps1'
    
  • Install some good interfaces for git:

1
2
apt-get install tig  # ncurses-based text-mode interface
apt-get install gitg # gtk visual repository viewer
  • Look for a file in a project:
1
2
3
4
grep -E --color=always \
  --exclude-dir=".git" --exclude-dir="log" --exclude-dir="tmp" \
  --exclude="#*#" \
  -rin search_term . | less -R
  • Make a single file full backup
1
2
git bundle create project.bundle --all # backup
git clone project.bundle dir           # restore

Source: cache username/pass via StackOverflow and GitHub; dev.to git terminal, side-by-side diff, add CR/LF files

See also: When to Use Git Reset, Git Revert & Git Checkout


~~~ * ~~~

Backup all mysql databases
mouse 364 · person cloud · link
Last update
2020-06-14
2020
06-14
« — »
1
2
3
4
5
6
7
8
# save
mysqldump \
  -u root -pROOTPASS \
  --all-databases --single-transaction | \
  xz > dbs.sql.xz

# restore
zcat dbs.sql.gz | mysql -u root -pROOTPASS

~~~ * ~~~

Create a multiresource favicon with imagemagic
mouse 13 · person cloud · link
Last update
2020-06-08
2020
06-08
« — »
1
2
3
4
convert src.png -scale 48x -transparent white f1.png
convert src.png -scale 32x -transparent white f2.png
convert src.png -scale 16x -transparent white f3.png
convert f?.png -colors 256 -transparent white favicon.ico

Source: gist @ pfig/mkfavicon.sh


~~~ * ~~~

Bash - check if script is alredy running
mouse 23 · person cloud · link
Last update
2020-06-03
2020
06-03
« — »
1
if [[ "`pidof -x $(basename $0) -o %PPID`" ]]; then exit; fi

Source: blog.jay2k1.com


~~~ * ~~~

UFW firewall setup
mouse 855 · person cloud · link
Last update
2020-05-25
2020
05-25
« — »

If you are using it on a VPS then you have to enable iptables NAT beforehand.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
apt-get install ufw

# write rules in /lib/ufw/user.rules
ufw reset # reset to defaults
# set our defaults
ufw default allow outgoing
ufw default deny  incoming
ufw allow 22/tcp        comment ssh
ufw allow 80/tcp        comment http
ufw allow 443/tcp       comment https
ufw allow 1194/udp      comment openvpn
ufw allow 1100:1200/tcp # port range (proto required23)
ufw allow 53            # allow both tcp and udp (eg: DNS)
ufw allow from 1.2.3.4  # single host
ufw allow from 192.168.1.0/24 # subnet
ufw allow from 1.2.3.4 to any port 22 proto tcp

# block an IP if it has attempted to initiate 6 or more
# connections in the last 30 seconds
ufw limit 22/tcp

# show rules added before enabling firewall
ufw show added

# remove rule
ufw status numbered
ufw delete row_number

# show rules
ufw show added
ufw show raw

# other reports
ufw show builtins
ufw show before-rules
ufw show user-rules
ufw show after-rules
ufw show logging-rules

# start/stop/status service
ufw enable
ufw disable
ufw status
ufw status verbose
ufw reload # reload cfg

# see logs
ufw logging low # off/low/medium/high/full
tail -f /var/log/ufw.log

# show blocked incoming ports messages from log/dmesg/journalctl
dmesg | grep UFW | sed -r 's/.*(IN=[^ ]+).*(PROTO=[^ ]+).*(DPT=[^ ]+) .*/\1 \2 \3/' | sort -u

Notes:

  1. The order of rules is critical in ufw/iptables as a packet will match the first rule, subsequent rules are ignored.
  2. If something is wrong with filtering/logs you can try to purge and reinstall uwf (especially after a distribution upgrade).

Source: CyberCiti, ArchLinux

See also: Lullabot