Skip to content

Instantly share code, notes, and snippets.

View bergpb's full-sized avatar
💻
https://blog.bergpb.dev

Lindemberg Barbosa bergpb

💻
https://blog.bergpb.dev
View GitHub Profile
@bergpb
bergpb / audit_mixin.py
Created April 25, 2019 16:56 — forked from techniq/audit_mixin.py
Useful SQLAlchemy Mixins
from datetime import datetime
from sqlalchemy import Column, Integer, DateTime, ForeignKey
from sqlalchemy.orm import relationship
from sqlalchemy.ext.declarative import declared_attr
from flask_security import current_user
class AuditMixin(object):
created_at = Column(DateTime, default=datetime.now)
updated_at = Column(DateTime, default=datetime.now, onupdate=datetime.now)

##Fixing npm permissions

You may receive an EACCES error when you try to install a package globally. This indicates that you do not have permission to write to the directories that npm uses to store global packages and commands.

You can fix this problem using one of three options:

Change the permission to npm's default directory. Change npm's default directory to another directory. Install Node with a package manager that takes care of this for you. You should back-up your computer before moving forward.

@bergpb
bergpb / install-docker.sh
Created February 11, 2019 02:14 — forked from sethbergman/install-docker.sh
Install Docker CE on Linux Mint 19
#!/usr/bin/env bash
# https://docs.docker.com/install/linux/docker-ce/ubuntu/
sudo apt-get install apt-transport-https ca-certificates curl software-properties-common
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -
sudo add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/ubuntu bionic stable"
sudo apt-get update
sudo apt-get install docker-ce
# https://docs.docker.com/compose/install/
@bergpb
bergpb / create-ruby-gem.md
Created January 15, 2019 18:08 — forked from kelvinst/create-ruby-gem.md
Como criar uma gem ruby?

Como criar uma gem ruby?

Escolhi tratar sobre esse assunto hoje simplesmente porque foi uma das primeiras coisas que me perguntei "como eu faço isso?" no mundo ruby. Acredito que muita gente se pergunte a mesma coisa e espero que eu possa ajudar em algo para elas. 😀

O que é uma gem?

Bem, se você é um programador java, você chama sua gem de jar, se você é um programador C#, você chama de dll. Resumindo, é uma lib, uma biblioteca contendo códigos que você pode reaproveitar importando em outros projetos.

E usar gems no ruby é muito fácil, se você já deu uma brincada com rails por exemplo, é só você adicionar o código gem 'nome_da_gem' no arquivo Gemfile que está no root, depois executar o comando bundle install para baixar sua gem do repositório e pronto, só sair usando a biblioteca!

@bergpb
bergpb / .pryrc
Created January 6, 2019 21:10 — forked from bespokoid/.pryrc
# === EDITOR ===
Pry.editor = 'vim'
# == Pry-Nav - Using pry as a debugger ==
Pry.commands.alias_command 'c', 'continue' rescue nil
Pry.commands.alias_command 's', 'step' rescue nil
Pry.commands.alias_command 'n', 'next' rescue nil
Pry.commands.alias_command 'r!', 'reload!' rescue nil
Pry.config.color = true
@bergpb
bergpb / validacao+mascara.js
Created November 20, 2018 02:15 — forked from ricardodantas/validacao+mascara.js
Máscara e validação de RG, CNPJ, CPF, etc...
// JavaScript Document
//adiciona mascara de cnpj
function MascaraCNPJ(cnpj){
if(mascaraInteiro(cnpj)==false){
event.returnValue = false;
}
return formataCampo(cnpj, '00.000.000/0000-00', event);
}
//adiciona mascara de cep
@bergpb
bergpb / npm-list-globally.md
Created September 23, 2018 17:37 — forked from brenopolanski/npm-list-globally.md
Listing globally installed NPM packages and version
npm list -g --depth=0
@bergpb
bergpb / gist:f98a2c8a6c7d471cbc9c9b0bc26e1017
Created September 21, 2018 02:49 — forked from thgaskell/gist:5987fccbd8473b5ef78f
Introduction to Sequelize Migrations

What are Migrations

Just like how we use Git to version control source code, we use migrations to manage the state of our database schemas.

I'm not really sure what that means...

Imagine you're working on project with another developer, and you're both tasked with creating a specific part of an event planning application. Let's say you are in charge of creating the Users and your friend is going to create the Events.

Let's say you and your friend divided the work in a way so that neither of you will have to to use each other's code to finish your tasks. While you're working on your part of the application, you only really need to touch the Users table when you are working with the database.

Before you begin

Make sure that the project you are in is a node project (it has a package.json) and you have already installed and initialized sequelize (npm install --save sequelize, sequelize init). Also make sure that your config.json file has the correct credentials to connect to your database.

@bergpb
bergpb / index.md
Created August 23, 2018 11:19 — forked from rstacruz/index.md
Rails models cheatsheet

Rails Models

Generating models

$ rails g model User

Associations

belongs_to

has_one

@bergpb
bergpb / gist:28a6044ac2c51ecaa9e395c1dae34ff6
Created August 21, 2018 13:45 — forked from sarahhodne/gist:1341827
Use pry for rails console
# Launch Pry with access to the entire Rails stack.
# If you have Pry in your Gemfile, you can pass: ./script/console --irb=pry
# instead. If you don't, you can load it through the lines below :)
rails = File.join(Dir.getwd, 'config', 'environment.rb')
if File.exist?(rails) && ENV['SKIP_RAILS'].nil?
require rails
if Rails.version[0..0] == '2'
require 'console_app'