Skip to content

Instantly share code, notes, and snippets.

Avatar
🎯
Focusing

Elinaldo Monteiro elinaldosoft

🎯
Focusing
View GitHub Profile
@elinaldosoft
elinaldosoft / filter_dict.py
Last active Feb 19, 2021
Filter dict is a method for search element in depth
View filter_dict.py
In [1]: def filter_dict(data: dict, extract):
...: try:
...: if isinstance(extract, list):
...: for i in extract:
...: result = filter_dict(data, i)
...: if result:
...: return result
...: keys = extract.split('.')
...: shadow_data = data.copy()
...: for key in keys:
@elinaldosoft
elinaldosoft / date_convert.py
Created May 5, 2020
Convert datetime to local date (Django)
View date_convert.py
import pytz
from django.utils import timezone
timezone.localtime(profile.updated_at.replace(tzinfo=pytz.UTC))
@elinaldosoft
elinaldosoft / dump-mysql.md
Last active Mar 12, 2020
Dump MYSQL - How to make a dump and restore in Mysql
View dump-mysql.md

You may need to install this package

  • sudo apt install mariadb-client-10.1 or
  • sudo apt install mysql-client

mysqldump --host=127.0.0.1 -u username -p database > database.sql

Restore Backup

mysql -u user -p database < database.sql

@elinaldosoft
elinaldosoft / restore-redis-backup.md
Last active Mar 5, 2020
Restore dump.rdb redis Mac OS X
View restore-redis-backup.md

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

@elinaldosoft
elinaldosoft / code.sh
Created Jan 28, 2020
Library not loaded: libcrypto.1.1.dylib
View code.sh
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 / example.rb
Created Mar 27, 2019
Release deploy, sentry by capistrano 3
View example.rb
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 / .pylintrc
Created Dec 11, 2018 — 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
View .pylintrc
[MASTER]
# Specify a configuration file.
#rcfile=
# Python code to execute, usually for sys.path manipulation such as
# pygtk.require().
#init-hook=
# Profiled execution.
View sql_custom.py
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 / rails_annotations.md
Created May 9, 2018 — forked from daltonjorge/rails_annotations.md
Explicações de conceitos do Rails e outras infos úteis.
View rails_annotations.md

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
@elinaldosoft
elinaldosoft / cors.conf
Created Aug 29, 2017
CORS on Nginx The following Nginx configuration enables CORS, with support for preflight requests.
View cors.conf
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;
}
}