Wednesday, December 7, 2016

Simple Shortcuts for Docker and K8s Ops

If you frequently work with the Docker/Kubernetes (or OpenShift) stack, you may find the following shortcut commands handy:

# aliases for kubectl commands

# for operations on kube-system namespace, e.g. kubesys get pods == kubectl get pods --namespace=kube-system
alias kubesys='kubectl --namespace=kube-system'

# resource getters
alias pods='kubectl get pods'
alias logs='kubectl logs'
alias get='kubectl get'
alias desc='kubectl describe'
alias svc='kubectl get svc'
alias rc='kubectl get rc'
alias rs='kubectl get rs'
alias dep='kubectl get deployment'
alias nodes='kubectl get nodes'

# edit/delete ops
alias del='kubectl delete'
alias deldep='kubectl delete deployment'
alias editdep='kubectl edit deployment'
alias edit='kubectl edit'

# open a shell to a running pod
alias kssh='kubectl exec -it'


# aliases for Docker control/management commands

# list Docker images
alias dimg='docker images'

# clean dangling images (https://github.com/docker/docker/issues/8926)
alias dclean='docker rmi -f `docker images -f "dangling=true" -q`'

# start a new container with a shell, and discard it after exit from the shell
alias drun='docker run --rm -it --entrypoint=sh'


# service control for an all-in-one K8s node (master + minion on same machine)

# starting the full stack
alias kreboot='for i in etcd flanneld docker kube-apiserver kube-controller-manager kube-scheduler kube-proxy kubelet; do sudo service $i restart; service $i status; done'

# stopping the full stack
alias kdown='for i in etcd flanneld docker kube-apiserver kube-controller-manager kube-scheduler kube-proxy kubelet; do sudo service $i stop; done'

# checking status of all required services (any unavailability will be displayed in red)
alias kstat='for i in etcd flanneld docker kube-apiserver kube-controller-manager kube-scheduler kube-proxy kubelet; do service $i status | grep -B2 "Active:" | grep -v "Loaded:" | grep -E "inactive|exited|$"; done'

Saturday, December 3, 2016

Too Many Friends Spoil TheFacebook: The (Less Painful) Way to Unfriend Multiple FB Friends

Your Facebook connections can easily grow in size to thousands, and often it is too late when you recognize that you actually know only a few dozens of them personally! If you face such a scenario and are trying to find an easy way to unfriend as many of them as possible, this post is for you.

Due to obvious reasons, FB does not offer a bulk unfriend feature (and will probably not offer one in years to come). Moreover, due to privacy concerns, many people are still afraid of using the bulk unfriend apps and scripts (though they are quite plentiful these days).

This post gives you a pretty good overview of the options available for bulk unfriending on FB. One of the easiest way you can unfriend multiple friends with least overhead (in terms of the number of clicks and page refreshes) is via the Friends page on FB mobile site. However, as of now, even this involves 2 clicks per each friend: the Friends button followed by the Unfriend list entry. With thousands of friends to go through (since you never know when a real friend would pop up inside the vast list of fakes and unknowns), this could easily put you down.

However, combining the above approach with the following script, you can cut down the process to a simple click of the Yes/No button for each friend; or, more conveniently, a press of Enter (yes) or Esc (no) keys. The script is nothing fancy; no explicit access to your FB account or anything, just plain JavaScript that manipulates the page DOM.

// run on the page https://x.facebook.com/friends/center/friends/?mff_nav=1
btns = document.querySelectorAll("button._56bt");
i = parseInt(prompt("resume from"));
for (i += (1 - i % 2); i < btns.length; i += 2) {
	btns[i].click();
	go = prompt("Unfriend " + btns[i].parentElement.parentElement.parentElement.parentElement.parentElement.children[1].children[0].children[0].textContent + "?");
	if (go != null) {
		if (go.length > 0) {
			break;
		}
		document.querySelectorAll('a[data-sigil="touchable touchable mflyout-remove-on-click m-unfriend-request"]')[0].click();
	}
	console.log(i);
}

For use, navigate to the Friend list page (https://x.facebook.com/friends/center/friends/?mff_nav=1), open the browser's web console (F12), paste the script and press Enter.

At startup, the script asks for a starting index, which can be useful if you want to stop the process and resume it at a later time. The script prints a numeric index after each confirmation, and you can simply provide the last-printed index to resume from that point. You can stop the process anytime by typing some text into the input field of the confirmation dialog and pressing OK (in which case nothing would be done to the friend currently being displayed). (Please note that this index would no longer be valid if you have reloaded the page after unfriending some friends, in which case the unfriended ones would already have been removed from the list.)

Before you run the script, make sure that you scroll down the page as far down as required (the page only loads a limited number of friend entries, and dynamically loads more friends only after you have scrolled to the bottom).

Disclaimer: The script has been tested only on Firefox browser so far. As always, use at your own risk!