Skip to content

Instantly share code, notes, and snippets.

View diegobarros0701's full-sized avatar
🎯
Focusing

Diego Barros diegobarros0701

🎯
Focusing
View GitHub Profile
@diegobarros0701
diegobarros0701 / ror-mysql-environment.sh
Last active October 5, 2017 16:43
Set up Ruby and Rails + MySQL
#!/bin/bash
echo "Setting up RoR and MySQL environment"
echo "Updating repositories..."
if ! sudo apt-get update
then
echo "Can't update the repository."
exit 1
@diegobarros0701
diegobarros0701 / typeahead-example.js
Created October 8, 2017 23:17
Example of how to use typeahead remote
$(document).ready(() => {
initializeTypeahead('/materias/buscar', '/materias', '#subject_study_plan')
});
function initializeTypeahead(remote_url, prefetch_url, selector) {
var subjects = new Bloodhound({
datumTokenizer: Bloodhound.tokenizers.obj.whitespace('name'),
queryTokenizer: Bloodhound.tokenizers.whitespace,
@diegobarros0701
diegobarros0701 / ar_migrate.rb
Created October 12, 2017 18:12 — forked from icyleaf/ar_migrate.rb
ActiveRecord type of integer (tinyint, smallint, mediumint, int, bigint)
# activerecord-3.0.0/lib/active_record/connection_adapters/mysql_adapter.rb
# Maps logical Rails types to MySQL-specific data types.
def type_to_sql(type, limit = nil, precision = nil, scale = nil)
return super unless type.to_s == 'integer'
case limit
when 1; 'tinyint'
when 2; 'smallint'
when 3; 'mediumint'
when nil, 4, 11; 'int(11)' # compatibility with MySQL default
@diegobarros0701
diegobarros0701 / ror-nginx-unicorn.md
Created November 5, 2017 00:40
RoR with Nginx and Unicorn

Nginx configuration

Add the following code in nginx.conf, inside http block

upstream rails {
  # Path to Unicorn socket file
  server unix:/home/username/project_name/shared/sockets/uni$
}
https://www.codecademy.com/pt-BR/articles/deploy-rails-to-heroku
@diegobarros0701
diegobarros0701 / management.rb
Created May 16, 2018 00:30
Session management rails
class ApplicationController < ActionController::Base
before_action :validate_session
def validate_session
if session[:user].nil?
redirect_to new_session_path if controller_name != 'sessions'
else
redirect_to home_index_path if controller_name == 'sessions' && action_name != 'destroy'
end
end
@diegobarros0701
diegobarros0701 / Dockerfile
Last active June 18, 2019 01:14
docker-compose and Dockerfile for RoR environment
FROM ruby:2.6
RUN apt-get update -qq && apt-get install -y nodejs
RUN mkdir /app
WORKDIR /app
COPY Gemfile /app/Gemfile
COPY Gemfile.lock /app/Gemfile.lock
FROM ruby:2.5
RUN apt-get update -qq && apt-get install -y nodejs postgresql-client
RUN mkdir /app
WORKDIR /app
COPY Gemfile /app/Gemfile
COPY Gemfile.lock /app/Gemfile.lock
@diegobarros0701
diegobarros0701 / instructions.md
Last active September 4, 2019 23:58
Disable Docker's iptables and use UFW

Disable Docker's iptables

CentOS 7

sudo mkdir /etc/systemd/system/docker.service.d
sudo nano /etc/systemd/system/docker.service.d/iptables-disabled.conf

Put this config on it