Skip to content

Instantly share code, notes, and snippets.

View guihatano's full-sized avatar
🏠
Working from home

Guilherme Y. Hatano guihatano

🏠
Working from home
View GitHub Profile
@guihatano
guihatano / replace-debian-with-arch.txt
Created February 1, 2016 21:20 — forked from m-ou-se/replace-debian-with-arch.txt
Instructions to replace a live Debian installation with Arch
# Download latest archlinux bootstrap package, see https://www.archlinux.org/download/
wget http://ftp.nluug.nl/os/Linux/distr/archlinux/iso/2016.01.01/archlinux-bootstrap-2016.01.01-x86_64.tar.gz
# Make sure you'll have enough entropy for pacman-key later.
apt-get install haveged
# Install the arch bootstrap image in a tmpfs.
mount -t tmpfs none /mnt
cd /mnt
tar xvf ~/archlinux-bootstrap-2016.01.01-x86_64.tar.gz --strip-components=1
@guihatano
guihatano / bootstrap_pagination_helper.rb
Last active June 22, 2017 12:23 — forked from artanikin/bootstrap_pagination_helper.rb
Will_paginate bootstrap 4 renderer
module BootstrapPaginationHelper
class LinkRenderer < WillPaginate::ActionView::LinkRenderer
protected
def page_number(page)
if page == current_page
link(page, "#", :class => 'active')
else
link(page, page, :rel => rel_value(page))
end
@guihatano
guihatano / divide_text_helper.rb
Last active September 22, 2017 17:30
Ruby On Rails code used to divide a html text with <p> tags. It is just a piece of code, you can copy and paste in a helper.
# After some research on how to divide a text with html tags my final solution is here
# this should work with strings.
# If you found a better solution, please let me know.
def divided_text(text)
# we have the start index of </p>, so we need do +3 to get the end
middle_index = middle_paragraph_index(text)+3
first_text = text[0..middle_index]
# and here we have the '>' so we need do +1
second_text = text[middle_index+1..-1]
@guihatano
guihatano / Rails-RestClient-with-mailgun.rb
Last active April 10, 2018 23:24
Rails using RestClient to call mailgun with attachment. When I was searching I just found same ways using RestClient::Request.execute, so I'm sharing this other way
require 'json'
result = RestClient.post "https://api:key-xxxxxxxxx-xxxxxxx@api.mailgun.net/v2/domain.com/",
:from => "YourDomain <your-email@domain.com>",
:to => "to-email@email.com",
:subject => "Mailgun with attachment",
:text => "Hello, Put something here",
:multipart => true,
:attachment => File.new('path/to/file', 'rb')
@guihatano
guihatano / postgres_docker_restore.md
Last active April 13, 2020 17:19
Restore database with pg_restore

pg_restore --verbose --clean --no-acl --no-owner -n public -h db -U loldesign -d mcr_development --port 5432 ./dbdump

On Docker

docker-compose run mcr pg_restore --verbose --clean --no-acl --no-owner -n public -h db -U loldesign -d mcr_development --port 5432 ./dbdump

With text .sql bkp

cat your_dump.sql | docker exec -i your-db-container psql -U postgres

Backup database:

@guihatano
guihatano / 01-safe-download.rb
Created January 14, 2019 20:06 — forked from janko/01-safe-download.rb
A safe way in Ruby to download a file to disk using open-uri (with/without comments)
require "open-uri"
require "net/http"
Error = Class.new(StandardError)
DOWNLOAD_ERRORS = [
SocketError,
OpenURI::HTTPError,
RuntimeError,
URI::InvalidURIError,
@guihatano
guihatano / download_pics.sh
Last active June 5, 2019 01:41
script to download pictures from an event
#!/bin/bash
#kendo_start 8866
#kendo_last 9079
#8814
initial_pic=8866
#last_pic=9181
last_pic=9079
url="http://www.saocarlos.sp.gov.br/images/stories/abril2019/MESDASARTESMARCIAIS/DSC_"
@guihatano
guihatano / mysql-docker.sh
Created June 14, 2019 14:30 — forked from spalladino/mysql-docker.sh
Backup and restore a mysql database from a running Docker mysql container
# Backup
docker exec CONTAINER /usr/bin/mysqldump -u root --password=root DATABASE > backup.sql
# Restore
cat backup.sql | docker exec -i CONTAINER /usr/bin/mysql -u root --password=root DATABASE
@guihatano
guihatano / load_yml_with_env.rb
Last active March 12, 2020 12:49
Use ENV on .yml files
require 'dotenv/load'
configuration_file = File.join(File.expand_path('..', __FILE__), 'config.yml')
configuration = YAML.load(File.read(configuration_file).gsub(/\<\%.*\[\'([^\']+)\'\].*\%\>/) { ENV[$1] } )
@guihatano
guihatano / depends_on.js
Created August 28, 2020 00:10 — forked from masonjm/depends_on.js
Show/Hide form fields based on the value in another field.
(function( $ ){
$.fn.dependsOn = function(element, value) {
var elements = this;
var hideOrShow = function() {
var $this = $(this);
var showEm;
if ( $this.is('input[type="checkbox"]') ) {
showEm = $this.is(':checked');
} else if ($this.is('select')) {