2015/08/17
2015/07/03
Bash: init from arg
Initialize from argument:
TEST=$(test -n "$1" && echo $1) || { echo "Usage: $0 <path_to_file>"; exit; }
test -z $1 && echo "Usage: $0 <path_to_file>" && exit
TEST=$1
TEST=$(test -n "$1" && echo $1) || { echo "Usage: $0 <path_to_file>"; exit; }
test -z $1 && echo "Usage: $0 <path_to_file>" && exit
TEST=$1
2015/06/25
Divide with floating point
awk 'BEGIN {printf "%.2f \n", (11.226 - 8.342)/11.226*100}'
awk 'BEGIN {print (11.226-8.342)/11.226*100}'
Rounding up works by default:
awk 'BEGIN {printf "%.3f \n", (11.226 - 8.342)/11.226*100}'
awk 'BEGIN {print (11.226-8.342)/11.226*100}'
Rounding up works by default:
awk 'BEGIN {printf "%.3f \n", (11.226 - 8.342)/11.226*100}'
2015/06/12
Filter STDERR only
$ cat warn.pl
#!/usr/bin/env perl
print STDERR "warnings all over the place\n";
print STDOUT "standard output to file descriptor 1\n";
$ exec 3>&1; ./warn.pl 2>&1 >&3 3>&- | awk '{print $5}' 3>&-; exec 3>&-
standard output to file descriptor 1
place
#!/usr/bin/env perl
print STDERR "warnings all over the place\n";
print STDOUT "standard output to file descriptor 1\n";
$ exec 3>&1; ./warn.pl 2>&1 >&3 3>&- | awk '{print $5}' 3>&-; exec 3>&-
standard output to file descriptor 1
place
2015/05/26
.bashrc
~/.bashrc
~/.bash_profile
export PS1="\[\033[36m\]\u\[\033[m\]@\h:\[\033[32m\]\w\[\033[m\]\$ "
export PS1="\[\033[36m\]\A \[\033[32m\]\w/ \[\033[33m\]\$ \[\033[m\]"
export PS1="\[\033[32m\]\w/ \[\033[33m\]\$ \[\033[m\]"
export CLICOLOR=1
export LSCOLORS=ExFxBxDxCxegedabagacad
alias ls='ls -GFh'
alias l='ls -l'
alias md='mkdir -p'
alias ..='cd ..'
alias grep='grep --color=auto -n'
export PS1="\[\033[36m\]\A \[\033[32m\]\w/ \[\033[33m\]\$ \[\033[m\]"
export PS1="\[\033[32m\]\w/ \[\033[33m\]\$ \[\033[m\]"
export CLICOLOR=1
export LSCOLORS=ExFxBxDxCxegedabagacad
alias ls='ls -GFh'
alias l='ls -l'
alias md='mkdir -p'
alias ..='cd ..'
alias grep='grep --color=auto -n'
2015/05/13
Oracle
select now():
select to_char(sysdate, 'mm-dd-yyyy hh24:mi:ss') "now" from dual;
select last row:
select to_char(sysdate, 'mm-dd-yyyy hh24:mi:ss') "now" from dual;
select last row:
select * from table where id = (select max(id) from table);
2015/05/07
Git
Current branch
git rev-parse --abbrev-ref HEAD
awk -F/ "{print \$NF}" .git/HEAD
Log
git log -1
git show 2a32e8590d5c00364b3c025f4c5a08f7aed26fd8
git log -- oneline -- abbrev - commit -- all -- graph
Show
git show f1ec7a9:lib/perl/Module.pm
Show changes history
git log -GMyChangedString -p
Show file history
commit history
git log -- filename
commit history and diffs
git log -p filename
tig filename, then j, k, d, q
To resolve Ctrl+Y in tig:
stty -a | grep dsusp
stty dsusp undef
stty -a | grep dsusp
Rename a branch
git branch -m branch-old branch-new
git push origin :branch-old
git push --set-upstream origin branch-new
Revert a merge to master
git revert -m 1 d33e978a8be12e8023dac8aba2cc126098dfa15d
(where d33e97... is the merge commit)
Revert commit
git revert <hash>
Delete a branch
git branch -D bugfix
git push origin --delete bugfix
Revert branch to remote
git reset --hard origin/bugfix
Resolve a file (ours is HEAD, theirs is trying to merge into HEAD)
git checkout --ours file.c
git checkout --theirs file.c
git add file.c
git commit -m 'File added'
Named stashes
git stash save "guacamole sauce WIP"
git stash apply stash^{/guacamo}
Git patch
git format-patch branch-18 --stdout > 18.patch
git format-patch HEAD^ --stdout > 18.patch
git apply --stat 18.patch
git apply --check 18.patch
git apply 18.patch
Git diff
git diff --stat -p master..branch
git diff branch^..branch
git diff HEAD~1 --stat
Git bisect
git log --since=1.weeks --reverse | head -n3
git bisect good <hash>
git bisect run my_script arguments
git bisect reset
Git force push
To force a push to only one branch, use a + in front of the refspec to push
git push origin +branch
git push --force-with-lease origin branch
If git lock occurs
ps -ef | grep git
rm .lock
git fetch --all --prune
(cleans up old branches locally that are no longer on the git remote server)
git checkout branch
git pull
Bring back the removed file
Existing commit
get a list of removed files
git checkout HEAD
OR
git checkout --
then restore needed file
git checkout HEAD file1 file2
OR
git checkout -- file1 file2
OR
git checkout HEAD^ -- file1 file2 file3
Previous commit
git reset HEAD^ -- file1 file2
git checkout -- file1 file2
Previous commits
git reset HEAD~4 -- file1 file2
git checkout -- file1 file2
How many commits is HEAD far away from origin/master?
git rev-list --count HEAD ^origin/master
Clean git dangling objects
git fsck
git gc --prune=now
Rebasing a big big branch
http://blog.appsignal.com/blog/2016/09/27/git-rebasing-strategies.html
Advanced Git commands
https://hackernoon.com/lesser-known-git-commands-151a1918a60
Git notifications link:
https://github.com/notifications/participating
Git pull requests link:
https://github.com/pulls/mentioned
Hide Whitespace Noise:
git diff -w
git show -w
?w=1
Show Changed Words:
git diff --word-diff
Which Branches You Recently Worked On:
recent = ! git for-each-ref --count=10 --sort=-committerdate refs/heads/ --format="%(refname:short)"
Remind Yourself What You’ve Been Up To:
git log --all --oneline --no-merges --author=<your email address>
Current hash:
current = ! git log -1 --pretty=oneline | cut -d' ' -f1
git rev-parse HEAD
Empty commit:
git commit --allow-empty -m "trigger build"
Lines removed so far:
git log --author='Per List' --after='2000-01-01' --word-diff --unified=0 | sed -ne '/^\[-/p' | sed -e '/{+/d' | wc -l
Git CRLF mess:
https://stackoverflow.com/questions/10418975/how-to-change-line-ending-settings
git rev-parse --abbrev-ref HEAD
awk -F/ "{print \$NF}" .git/HEAD
Log
git log -1
git show 2a32e8590d5c00364b3c025f4c5a08f7aed26fd8
git log -- oneline -- abbrev - commit -- all -- graph
Show
git show f1ec7a9:lib/perl/Module.pm
Show changes history
git log -GMyChangedString -p
Show file history
commit history
git log -- filename
commit history and diffs
git log -p filename
tig filename, then j, k, d, q
To resolve Ctrl+Y in tig:
stty -a | grep dsusp
stty dsusp undef
stty -a | grep dsusp
git branch -m branch-old branch-new
git push origin :branch-old
git push --set-upstream origin branch-new
Revert a merge to master
git revert -m 1 d33e978a8be12e8023dac8aba2cc126098dfa15d
(where d33e97... is the merge commit)
Revert commit
git revert <hash>
Delete a branch
git branch -D bugfix
git push origin --delete bugfix
Revert branch to remote
git reset --hard origin/bugfix
Resolve a file (ours is HEAD, theirs is trying to merge into HEAD)
git checkout --ours file.c
git checkout --theirs file.c
git add file.c
git commit -m 'File added'
Named stashes
git stash save "guacamole sauce WIP"
git stash apply stash^{/guacamo}
Git patch
git format-patch branch-18 --stdout > 18.patch
git format-patch HEAD^ --stdout > 18.patch
git apply --stat 18.patch
git apply --check 18.patch
git apply 18.patch
Git diff
git diff --stat -p master..branch
git diff branch^..branch
git diff HEAD~1 --stat
Git bisect
git log --since=1.weeks --reverse | head -n3
git bisect start
git bisect badgit bisect good <hash>
git bisect run my_script arguments
git bisect reset
Git force push
To force a push to only one branch, use a + in front of the refspec to push
git push origin +branch
git push --force-with-lease origin branch
If git lock occurs
ps -ef | grep git
rm .lock
git fetch --all --prune
(cleans up old branches locally that are no longer on the git remote server)
git checkout branch
git pull
Bring back the removed file
Existing commit
get a list of removed files
git checkout HEAD
OR
git checkout --
then restore needed file
git checkout HEAD file1 file2
OR
git checkout -- file1 file2
OR
git checkout HEAD^ -- file1 file2 file3
Previous commit
git reset HEAD^ -- file1 file2
git checkout -- file1 file2
Previous commits
git reset HEAD~4 -- file1 file2
git checkout -- file1 file2
How many commits is HEAD far away from origin/master?
git rev-list --count HEAD ^origin/master
Clean git dangling objects
git fsck
git gc --prune=now
Rebasing a big big branch
http://blog.appsignal.com/blog/2016/09/27/git-rebasing-strategies.html
Advanced Git commands
https://hackernoon.com/lesser-known-git-commands-151a1918a60
Git notifications link:
https://github.com/notifications/participating
Git pull requests link:
https://github.com/pulls/mentioned
Hide Whitespace Noise:
git diff -w
git show -w
?w=1
Show Changed Words:
git diff --word-diff
Which Branches You Recently Worked On:
recent = ! git for-each-ref --count=10 --sort=-committerdate refs/heads/ --format="%(refname:short)"
Remind Yourself What You’ve Been Up To:
git log --all --oneline --no-merges --author=<your email address>
Current hash:
current = ! git log -1 --pretty=oneline | cut -d' ' -f1
git rev-parse HEAD
Empty commit:
git commit --allow-empty -m "trigger build"
Lines removed so far:
git log --author='Per List' --after='2000-01-01' --word-diff --unified=0 | sed -ne '/^\[-/p' | sed -e '/{+/d' | wc -l
Git CRLF mess:
https://stackoverflow.com/questions/10418975/how-to-change-line-ending-settings
Subscribe to:
Posts (Atom)