Skip to content

Instantly share code, notes, and snippets.

View emanuelhfarias's full-sized avatar

Emanuel H. Farias emanuelhfarias

View GitHub Profile
@emanuelhfarias
emanuelhfarias / zsh_histogram.rb
Created March 9, 2018 02:39
zsh history histogram
#!/bin/ruby
require 'pry-byebug'
history_array = []
zsh_history_path = '~/.zhistory'
File.open(zsh_history_path).each do |line|
history_array << line[15..-2]
end
@emanuelhfarias
emanuelhfarias / gist:ca20acc392497268397bb80f856a89b5
Created February 13, 2017 03:01
[Rails] Valid params.permit mantaining the order of params
params = ActionController::Parameters.new( {sort: {year: 'desc', title: 'asc', author: 'desc'}} )
valid_sorts = ["author", "title", "year"]
passed_sorts = params[:sort].keys & valid_sorts # only permit valid sorts
params.permit(sort: passed_sorts)
@emanuelhfarias
emanuelhfarias / oracle_jre_on_fedora.sh
Created November 25, 2016 14:58
Install Oracle Java JRE on Fedora
#!/bin/bash
# Install Oracle Java JRE (runtime environment) on Fedora
# This is script is based on Fedy
# To change between java versions:
# $ alternatives --config java
CACHEDIR="/var/cache/java/jre"
@emanuelhfarias
emanuelhfarias / run_docker.sh
Created October 15, 2016 19:54
gdb inside a docker container
#!/bin/bash
docker run -it --security-opt seccomp:unconfined docker_image bash
@emanuelhfarias
emanuelhfarias / virtualbox_kernel_driver
Last active June 9, 2017 23:31
VirtualBox Kernel Driver update
# using Fedora
# every time you update the Linux Kernel you have to recompile the VirtualBox Kernel driver
# first install/upgrade the kernel-devel and headers
sudo dnf install kernel-devel kernel-headers
# make sure you have installed akmod-VirtualBox (and DON'T have installed dkms)
sudo dnf install akmod-VirtualBox
sudo akmods
sudo modprobe vboxdrv
# ----> Ruby File: hi.rb
# Importing code from Python to Ruby
p obj = eval(`python hi.py`.chomp)
# Exporting code from Ruby to Python
p my_array = [[1,2,3],["hi", 1.5]]
# Executing Python code 'inside' Ruby passing args from ruby variables to python
p obj = eval(`python hi.py '#{my_array}'`.chomp)
@emanuelhfarias
emanuelhfarias / debugger.py
Created August 31, 2016 22:59
Python Debugger like pry-byebug
# install ipdb with pip
import ipdb
# place the following command where you want to stop
ipdb.set_trace(context=10)
sudo chsh -s `which zsh` <username>
# You must log out and log back in.
@emanuelhfarias
emanuelhfarias / change_docker_images_directory.sh
Last active May 19, 2020 22:43
How to change the Docker Images directory
#!/bin/bash
# How to change the Docker images directory (default dir=/var/lib/docker)
# The simplest method is to create a symbolic link that maps your destination partition and the original docker images directory
# see REF: https://forums.docker.com/t/how-do-i-change-the-docker-image-installation-directory/1169
# remove all containers
docker ps -aq | xargs docker rm
# stop docker daemon
systemctl stop docker