Skip to content

Instantly share code, notes, and snippets.

View elinaldosoft's full-sized avatar
🎯
Focusing

Elinaldo Monteiro elinaldosoft

🎯
Focusing
View GitHub Profile
@elinaldosoft
elinaldosoft / override_django_object_seralizer.py
Created July 10, 2017 18:23
Override Django Object Serializer to get rid of specified model
from django.http import JsonResponse
from django.shortcuts import render
from django.core.serializers.python import Serializer
from .models import User
class MySerializer(Serializer):
def get_dump_object(self, obj):
return {
"id": obj._get_pk_val(),
# -*- coding: utf-8 -*-
import logging
logger = logging.getLogger(__name__)
# Define your item pipelines here
#
# Don't forget to add your pipeline to the ITEM_PIPELINES setting
# See: http://doc.scrapy.org/en/latest/topics/item-pipeline.html
class CamaraPipeline(object):
@elinaldosoft
elinaldosoft / settings.py
Last active August 12, 2017 15:35
Enable log of querys in Django!
LOGGING = {
'version': 1,
'disable_existing_loggers': False,
'handlers': {
'console': {
'class': 'logging.StreamHandler',
},
},
'loggers': {
'django.db.backends': {
@elinaldosoft
elinaldosoft / cors.conf
Created August 29, 2017 19:38
CORS on Nginx The following Nginx configuration enables CORS, with support for preflight requests.
location ~* ^.+\.(ttf|oft|eot|woff|svg|woff2)$ {
if ($http_origin ~* (https?://[^/]*\.domain.com(:[0-9]+)?)$) {
add_header 'Access-Control-Allow-Origin' "$http_origin" always;
add_header 'Access-Control-Allow-Credentials' 'true' always;
add_header 'Access-Control-Allow-Methods' 'GET, POST, PUT, DELETE, OPTIONS' always;
add_header 'Access-Control-Allow-Headers' 'Accept,Authorization,Cache-Control,Content-Type,DNT,If-Modified-Since,Keep-Alive,Origin,User-Agent,X-Requested-With' always;
}
}
@elinaldosoft
elinaldosoft / rails_annotations.md
Created May 9, 2018 21:16 — forked from daltonjorge/rails_annotations.md
Explicações de conceitos do Rails e outras infos úteis.

Active Record

É um design pattern que o Rails implementa a partir da gem ActiveRecord.

Serve para conectar a camada Model da aplicação com tabelas do database, para assim criar um modelo de domínio persistível, onde a lógica (Model) e dados (BD) são apresentados em uma única solução.

Já persiste no BD:

obj.create
from django.db import models, connection
class Assinantes(models.Model):
id = models.AutoField(db_column='ID', primary_key=True) # Field name made lowercase.
msisdn = models.BigIntegerField(unique=True, blank=True, null=True)
# faixaid = models.ForeignKey('Faixa', models.DO_NOTHING, db_column='faixaID', blank=True, null=True) # Field name made lowercase.
faixaid = models.IntegerField(db_column='faixaID', blank=True, null=True) # Field name made lowercase.
docnum = models.CharField(db_column='docNum', max_length=28, blank=True, null=True) # Field name made lowercase.
offeramount = models.DecimalField(db_column='offerAmount', max_digits=7, decimal_places=2, blank=True, null=True) # Field name made lowercase.
@elinaldosoft
elinaldosoft / .pylintrc
Created December 11, 2018 21:16 — forked from sblask/.pylintrc
PyLint configuration file, initially generated with `pylint --generate-rcfile ` and then edited. See http://docs.pylint.org/features.html for disabled messages
[MASTER]
# Specify a configuration file.
#rcfile=
# Python code to execute, usually for sys.path manipulation such as
# pygtk.require().
#init-hook=
# Profiled execution.
@elinaldosoft
elinaldosoft / example.rb
Created March 27, 2019 14:46
Release deploy, sentry by capistrano 3
require 'net/https'
require 'uri'
require 'json'
namespace :sentry do
task :notify_deployment do
run_locally do
puts 'Notifying Sentry of release...'
uri = URI.parse(SENTY_URL)
http = Net::HTTP.new(uri.host, uri.port)
@elinaldosoft
elinaldosoft / code.sh
Created January 28, 2020 22:45
Library not loaded: libcrypto.1.1.dylib
brew remove openssl
brew install openssl
ln -s /usr/local/Cellar/openssl@1.1/1.1.1d/lib/libcrypto.1.1.dylib /usr/local/lib
@elinaldosoft
elinaldosoft / restore-redis-backup.md
Last active March 5, 2020 12:47
Restore dump.rdb redis Mac OS X

Stop Redis

brew redis-server stop

Move backup to directory db redis

mv dump.202003050300.rdb /usr/local/var/db/redis

Backup dump.rdb

mv dump.rdb bk.dump.rdb

Rename restore backup to dump.rdb

mv dump.202003050300.rdb dump.rdb

Start Server

brew redis-server start