Skip to content

Instantly share code, notes, and snippets.

View hectorcanto's full-sized avatar

Héctor Canto hectorcanto

View GitHub Profile
@hectorcanto
hectorcanto / Vagrantfile
Last active August 29, 2015 14:25
A sample of Vagrantfile in construction
VAGRANTFILE_API_VERSION = "2"
Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|
config.vm.box = "official/centos7"
config.vm.box_url = "https://atlas.hashicorp.com/centos/boxes/7/versions/1505.01/providers/virtualbox.box"
# NETWORK
config.vm.network "private_network", ip: "192.168.56.102"
# Explictly set IP
@hectorcanto
hectorcanto / inventory.tf
Last active April 5, 2024 19:38
Produce an Ansible inventory from a Terraform template
data "template_file" "inventory" {
template = "${file("inventory.tpl")}"
vars {
backend_ip = "${aws_instance.backend.public_ip}"
frontend_ip = "${aws_instance.frontend.public_ip}"
landing_ip = "${aws_instance.landing.public_ip}"
key_path = "${var.instance_key_path}"
}
}
@hectorcanto
hectorcanto / clean-dockers.sh
Created September 27, 2017 11:23
Docker clean everything
docker stop $(docker ps -aq)
docker rm $(docker ps -aq)
docker rmi $(docker images -q)
@hectorcanto
hectorcanto / .bash_aliases
Last active December 18, 2018 11:48
Configure git aliases for faster CLI input
alias g=git
__git_complete g _git
alias gti=git
__git_complete gti _git
@hectorcanto
hectorcanto / custom_resolution.sh
Last active March 27, 2018 09:02
How to create and persist a custom resolution in Ubuntu 16.
# Based on http://ubuntuhandbook.org/index.php/2017/04/custom-screen-resolution-ubuntu-desktop/
xrandr
# eDP-1, take note of the device you want to modify
cvt 1408x792 # True 16:9 resolution: https://pacoup.com/2011/06/12/list-of-true-169-resolutions/
# Modeline "1408x792_60.00" 90.75 1408 1480 1624 1840 792 795 800 823 -hsync +vsync
sudo xrandr --newmode "1408x792_60.00" 90.75 1408 1480 1624 1840 792 795 800 823 -hsync +vsync
sudo xrandr --addmode eDP-1 "1408x792_60.00"
echo xrandr --newmode "1408x792_60.00" 90.75 1408 1480 1624 1840 792 795 800 823 -hsync +vsync >> ~/.profile
@hectorcanto
hectorcanto / locale.sh
Last active May 3, 2018 09:45
[Set locale in Ubuntu 15+] Not tested if persistent #locale #virtualenv #wip
export LANGUAGE=en_US.UTF-8
export LC_ALL=en_US.UTF-8
update-locale
@hectorcanto
hectorcanto / Bash hooks
Created April 26, 2018 09:23
Some hooks I have in my .bashrc
# Tab cycle but list option first
bind TAB:menu-complete
bind "set show-all-if-ambiguous on"
# git branch if in git
parse_git_branch() {
git branch 2> /dev/null | sed -e '/^[^*]/d' -e 's/* \(.*\)/ (\1)/'
}
PS1='${debian_chroot:+($debian_chroot)}\[\033[01;32m\]\u@\h\[\033[00m\]:\[\033[01;34m\]\w\[\033[00m\]\[\033[0;33m\]$(parse_git_branch)\[\033[0m\]\$ '
@hectorcanto
hectorcanto / git_tags.sh
Created May 8, 2018 14:20
[Git tag commands] #git #tags
# delete remote tag
git push origin :tagname
# push tags
git push --tags
git push --follow-tags
git config --global push.followTags true
@hectorcanto
hectorcanto / time_utils.py
Last active June 14, 2018 13:48
[Datetime utils] Datetime & timestamp utils for Python #py3 #datetime # utils
def dt2ts(dt: Optional[datetime]) -> Optional[int]:
return int(time.mktime(dt.timetuple())) if dt is not None else None
def dt2ts_ms(dt: Optional[datetime]) -> Optional[int]:
return dt2ts(dt) * 1000 if dt is not None else None
def ts2dt(ts: Optional[int]) -> Optional[datetime]:
return datetime.utcfromtimestamp(int(ts)) if ts is not None else None
def ts_ms2dt(ts: Optional[int]) -> Optional[datetime]:
@hectorcanto
hectorcanto / .activate.sh
Last active August 8, 2018 11:01
Scripts to create and activate virtualenvs according to env_$current_folder syntax
result=${PWD##*/}
folder=env_$result
path=env_$result/bin/activate
if [ ! -d "$folder" ];
then echo "Virtualenv not present in the current folder '$PWD'."
else . $path
fi