Skip to content

Instantly share code, notes, and snippets.

@Marlysson
Marlysson / fields.py
Created August 14, 2022 14:24
Custom fields django
from django.db import models
class ZipField(models.Field):
def __init__(self, length=8, *args, **kwargs):
self.length = length
super().__init__(*args, **kwargs)
def db_type(self, connection):
return f"char({self.length})"
@Marlysson
Marlysson / replica.py
Last active June 15, 2022 19:55
Replica de dados
from django.core import management
from pathlib import Path
class Command(management.base.BaseCommand):
def handle(self, *args, **options):
apps = ["core"]
models = ["core.ModelA", "core.ModelB"]
fixture_name = "audit"
@Marlysson
Marlysson / celledit-override.js
Last active March 29, 2022 18:42
tabCell function overriding
if (PrimeFaces.widget.DataTable) {
PrimeFaces.widget.DataTable.prototype.tabCell = function(celula, frente){
var celulaAlvo = frente ? celula.nextAll("td.ui-editable-column:first") : celula.prevAll("td.ui-editable-column:first");
if (celulaAlvo.length == 0) {
var linha = frente ? celula.parent().next() : celula.parent().prev();
celulaAlvo = frente ? linha.children("td.ui-editable-column:first") : linha.children("td.ui-editable-column:last");
}
@Marlysson
Marlysson / ZeroMQProvider.py
Last active February 16, 2022 09:00
Integrating ZeroMQ with Masonite
from masonite.providers import Provider
class ZeroMQProvider(Provider):
def __init__(self, application):
self.application = application
def register(self):
print("Starting zeromq")
import zmq
@Marlysson
Marlysson / MyProvider.py
Last active February 14, 2022 00:54
Scaffold to handle policies
class MyProvider(Provider):
def __init__(self, application):
self.application = application
def register(self):
Gate.register_policies([(Project, ProjectPolicy)])
def boot(self):
pass
@Marlysson
Marlysson / details.py
Created January 16, 2022 18:58
Details api masonite
# api.py
from masonite.routes import Route
ROUTES = [
Route.get('/podcasts', 'api.PodcastController@index')
]
# web.py
@Marlysson
Marlysson / baseDTO.java
Created October 14, 2021 00:53
Herança?
public String toJson() throws JsonProcessingException {
ObjectMapper mapper = new ObjectMapper();
return mapper.writeValueAsString(this);
}
public PessoaFisica toModel() {
SimpleDateFormat df = new SimpleDateFormat("dd/MM/yyyy");
ObjectMapper mapper = new ObjectMapper();
mapper.setDateFormat(df);
return mapper.convertValue(this, OBJ.class);
@Marlysson
Marlysson / csv.csv
Last active September 16, 2021 00:09
Challenge of pre process a csv file comma separated values with money cents with comma too
ITEM1 1 11 COMPRA1 444444 00 3312 22
ITEM1 1 11 COMPRA3 444444 00 3312 22
ITEM1 1 13 COMPRA2 444444 00 3312 22
ITEM1 1 90 COMPRA3 444444 00 3312 22
ITEM2 1 20 COMPRA2 444444 00 3312 22
ITEM2 2 19 COMPRA1 444444 00 3312 22
ITEM2 1 11 COMPRA1 444444 00 3312 22
ITEM2 1 12 COMPRA2 444444 00 3312 22
ITEM3 1 11 COMPRA1 444444 00 3312 22
ITEM3 5 60 COMPRA3 444444 00 3312 22
@Marlysson
Marlysson / models.py
Created July 16, 2021 00:37
Renderizando erro na view.
class ModelA(models.Model):
a = models.CharField()
b = models.CharField()
c = models.CharField()
def save(self, *args, **kwargs):
c = self.a + self.b
super().save(*args, **kwargs)
def validate(self, attrs):
whatsapp = attrs.get('whatsapp', self.object.whatsapp)
whatsapp_h = attrs.get('whatsapp_h', self.object.whatsapp_h)
prontuario = attrs.get("prontuario", self.object.prontuario
try:
obj = tb_Paciente.objects.filter(whatsapp=whatsapp, whatsapp_h=whatsapp_h, prontuario=prontuario).exists
()