setopt HIST_IGNORE_SPACE
brew upgrade postgresql
brew postgresql-upgrade-database
If you receive No Space left error on Docker this the brute force solution:
It would stop and delete ALL containers, images and volumes.
docker stop $(docker ps -aq); docker rm $(docker ps -aq); docker volume rm $(docker volume ls -qf dangling=true);docker system prune -af
If you have to run the same command repetitively over different input/inputs.
Example input:
c595270372e3
c04094382ae1
498a6505a1f7
4ac0e1872789
170a7f2ec51a
930743cb4e19
Command:
pbpaste | xargs -I id docker image rm id
Note: pbpaste is clipboard paste command for Mac, would be different for operating systems.
A bit of a hack, but we want to be notified if an item becomes available at IKEA.
This is just a shell script that should work on any *NIX that has curl installed.
This is how their API response looks like (replace th with your country code): https://www.ikea.com/th/en/iows/catalog/availability/S99067497
There are only two stores in Thailand, both of which are close enough to the Oozou office, we only care that it's available in one of those stores.
#!/usr/bin/env bash
url="https://www.ikea.com/th/en/iows/catalog/availability/$1"
# This is the string that we want to see changed
string="0"
while true; do
# Get the API response and return as string
text=$(curl -s "$url")
# Get a count of how many times the substring matches
count=`grep -o "$string" <<< "$text" | wc -l`
# If less than 2, then it's available!
if (( $count < 2 )); then
echo "AVAILABLE, yay.";
# Notify us via Slack
curl -X POST --data-urlencode "payload={\"channel\": \"…\", \"username\": \"ikea\", \"text\": \"Item $1 is now available at IKEA.\", \"icon_emoji\": \":shooping_bags:\"}" https://hooks.slack.com/services/…
break
else
# If not available, sleep for 30s
echo "$1 not in stock"
sleep 30
fi
done
Pass in your item ID to start:
$ ./check.sh S99067497
Occasionally an SSH session may become unresponsive. If I put my laptop to sleep this happens fairly often. Rather than killing the tab you can use SSH Escape Characters to kill the session
$ ~.
To view all escape characters check man ssh and search for ESCAPE CHARACTERS $ /ESCAPE CHARACTERS
I'd like to kill rails running w/specific port. (My laptop running several rails servers. )
kill -9 $(lsof -i :3000|grep ruby|head -1|awk '{print $2}')
Git allows you to create aliases internally through the config. Your global config should be located here ~/.gitconfig
[alias]
aliases = !git config --get-regexp 'alias.*' | colrm 1 6 | sed 's/[ ]/ = /' | sort
count = shortlog -sn
l = log
co = checkout
ca = commit -C HEAD --amend
c = commit
cm = commit -m
a = add
s = status
b = branch
p = push
mt = mergetool
dt = difftool
o = origin
rc = rebase --continue
rs = rebase --skip
pd = !git checkout develop && git pull origin develop && git branch --merged | grep -v '*' | grep -v 'master' | xargs git branch -d && git fetch --prune origin
pm = !git checkout master && git pull origin master && git branch --merged | grep -v '*' | grep -v 'develop' | xargs git branch -d && git fetch --prune origin
pr = pull-request -c -m
Most are self explanatory...
git pd (prune develop) - checks out to develop, fetches latest changes, deletes all stale branches except develop (will delete master too)
git pm (prune master) - does the same as prune develop for master
$ git log --diff-filter=D --summary --oneline
$ git log --oneline --all --grep=pretty
c198bb715 Make default expired description logic pretty
$ git branch --contains c198bb715
* deploy/staging
feature/ROC-3042
if ! type gem > /dev/null; then
echo 'gem command not found.'
fi
Handy git command for deleting all local git branches that already merged git branch --merged | egrep -v "(^\*|master|dev)" | xargs git branch -d
When you have Github's hub installed, you can get the ci-status of your current branch like this:
$ hub ci-status
pending
If you install watch (e.g. brew install watch) you can continuously see the state:
$ watch hub ci-status
I have a seperate file in my user folder named ~/.aliases. I use this to store all of my bash aliases. I use aliases a lot and add new ones regularly so I created a bash function to add new aliases on the fly.
addalias() {
echo 'alias '$1'="'$2'"' >> ~/.aliases
source ~/.aliases
}
Now you can add an alias from the terminal which will be available to the current session and all new sessions... shell $ addalias foo 'echo "bar"'
If I find myself using commands over and over I will create aliases shell alias g='git' alias b='bundle' alias be='bundle exec' alias bu='bundle update' alias r='bin/rails' alias rr='bin/rails routes' alias migration='bin/rails generate migration' alias migrate='bin/rails db:migrate; bin/rails db:migrate RAILS_ENV=test' alias rollback="rake db:rollback; RAILS_ENV=test rake db:rollback" alias push='git push origin HEAD' alias pr='git pull-request -c -m' alias ppr="git push origin HEAD && git pull-request -m" alias pulls='git browse -- pulls' alias prs='git pr list' pull() { git browse -- pull/'$1' } alias la='ls -a' alias ll='ls -al'
If you push some code and want to force push a previous commit you can do so with shell git push origin +commit_sha^:branch_name
Where git interprets sha^ as the parent of sha and + as a forced non-fastforward push.
You can also use HEAD^ where ^ is the parent of HEAD so HEAD^^^ would push the commit 3 commits before the current commit. e.g. shell git push origin +HEAD^^^:feature/i_did_an_oopsie
$ cp todo.txt !#:1.bak
cp todo.txt todo.txt.bak
NOTE: Actually you can use !#:1 in every command 'cause that's last argument passed to a command.
UPDATED: Now it works with zsh
$ git branch --merged | egrep -v 'master|develop' | xargs -n 1 git branch -d
You can safelist more branches in egrep -v 'master|develop|foo|bar'
Easily run the below command and get a diff version from the remote
$ git diff origin/master -- [local-path]
$ curl -X POST -H 'Content-type: application/json' --data '{"text": "Something important"}' https://hooks.slack.com/services/YOUR/TOKENIZED/URL
{ "text": "Hello, Slack!", "username": "WebhookBot", "icon_emoji": ":ghost:" }
{ "text": "Hello, World!" }
curl -X POST -H 'Content-Type: application/json' --data @message.json https://hooks.slack.com/services/YOUR/TOKENIZED/URL
Ever wanted to display the structure of the current directory except or two directories?
#NPM or yarn project
tree -I node_modules
# Elixir Mix project
tree -I 'deps|test'
You might be using dig to find out A/CNAME/MX etc records of a domain from DNS servers. But if you just want to get a quick overview, use host:
$ host oozou.com
oozou.com has address 52.89.55.136
oozou.com has address 35.165.206.160
oozou.com has address 34.212.209.65
oozou.com mail is handled by 1 aspmx.l.google.com.
oozou.com mail is handled by 5 alt1.aspmx.l.google.com.
oozou.com mail is handled by 5 alt2.aspmx.l.google.com.
oozou.com mail is handled by 10 aspmx2.googlemail.com.
oozou.com mail is handled by 10 aspmx3.googlemail.com.
lst() {
if [ "$1" != "" ] # or better, if [ -n "$1" ]
then
ls -R $1 | grep ":$" | sed -e 's/:$//' -e 's/[^-][^\/]*\//--/g' -e 's/^/ /' -e 's/-/|/'
else
ls -R | grep ":$" | sed -e 's/:$//' -e 's/[^-][^\/]*\//--/g' -e 's/^/ /' -e 's/-/|/'
fi
}
sh source ~/.zshrc
sh lst spec
sh lst
bash spec/ ├── controllers/ │ └── users/ ├── models/ └── views/
css spec |--controllers | |--users |--models |--views
sh sudo apt-get install tree
sh brew install tree
sh tree spec
Ever wanted to shorten a git command? You can go with shell alilas for sure but you have to always include context so that you don't forget what each ailas stands for but you can define your own commands in git using aliases.
git config --global alias.
For example; I'm too lazy to type git status so I want to shorten this to git s
git config --global alias.s status
And here we go now you can just type git s and get the status of current repository.
Open term (or equivalent) and paste the following:
aws s3 cp source.file s3://bucket/path/dest.file --acl public-read
Options for --acl parameters are:
# Find in which commit it's been deleted
$ git rev-list -n 1 HEAD --
4058ef780d2f6c4c6d57cfd7fd4ebe14c9dc28b3
# Restore it back
$ git checkout 4058ef780d2f6c4c6d57cfd7fd4ebe14c9dc28b3^ --
install hub first with brew: brew install hub then use a simple command, like at the example below: hub pull-request -m "best pr ever" -b oozou:develop -h feature/awesome-improvements
or even smarter:
hub pull-request -m "best pr ever" -b oozou:develop -h $(git rev-parse --abbrev-ref HEAD)
for more detailed info how to make pull requests see at hub pull-request --help
If you don't need the full git history for a repo you will be working on you can supply a clone depth to only clone x revisions of the repo.
git clone --depth=1 https://github.com/my/repo.git