Skip to content

Instantly share code, notes, and snippets.

View Marceloromeugoncalves's full-sized avatar

Marcelo Romeu Gonçalves Marceloromeugoncalves

  • Campos dos Goytacazes
View GitHub Profile
@Marceloromeugoncalves
Marceloromeugoncalves / index.html
Created July 18, 2024 00:46
Admin LTE 3 - CDN
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>AdminLTE 3 Dashboard</title>
<!-- AdminLTE CSS -->
<!DOCTYPE html>
<html>
<head>
<title>My Folium Map</title>
<!-- Importa o arquivo CSS do Leaflet -->
<link rel="stylesheet" href="https://unpkg.com/[email protected]/dist/leaflet.css" integrity="sha256-p4NxAoJBhIIN+hmNHrzRCf9tD/miZyoHS5obTRR9BMY=" crossorigin=""/>
<!-- Importa o arquivo JavaScript do Leaflet -->
<script src="https://unpkg.com/[email protected]/dist/leaflet.js" integrity="sha256-20nQCchB9co0qIjJZRGuk2/Z9VM+kNiyxNV1lvTlZBo=" crossorigin=""></script>
@Marceloromeugoncalves
Marceloromeugoncalves / models.py
Created April 28, 2023 18:01
Utilizar um banco de dados Oracle somente leitura com Django.
# models.py
from django.db import models
class MinhaTabela(models.Model):
campo1 = models.CharField(max_length=50)
campo2 = models.CharField(max_length=50)
class Meta:
managed = False
db_table = 'NOME_DA_TABELA_ORACLE' # Defina o nome da tabela no banco de dados Oracle
from collections import namedtuple
Local = namedtuple('Local', ['nome', 'latitude', 'longitude'])
locais = [
Local('Estátua da Liberdade, Nova York, EUA', 40.6892, -74.0445),
Local('Torre Eiffel, Paris, França', 48.8584, 2.2945),
Local('Opera House, Sydney, Austrália', -33.8568, 151.2153),
Local('Cristo Redentor, Rio de Janeiro, Brasil', -22.9519, -43.2105),
Local('Pirâmides de Gizé, Cairo, Egito', 29.9792, 31.1342),
@Marceloromeugoncalves
Marceloromeugoncalves / exemplo.py
Created March 15, 2022 18:36
Exemplo de conexão SSH com paramiko.
# pip install paramiko
import paramiko
address = '10.0.0.61'
username = 'root'
password = 'pythondevops'
ssh = paramiko.SSHClient()
ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
@Marceloromeugoncalves
Marceloromeugoncalves / estados_choices.py
Created March 3, 2022 03:53
Django - Choices para os estados brasilerios.
ESTADOS_CHOICES = [
['AC', 'Acre'],
['AL', 'Alagoas'],
['AP', 'Amapá'],
['AM', 'Amazonas'],
['BA', 'Bahia'],
['CE', 'Ceará'],
['ES', 'Espírito Santo'],
['GO', 'Goiás'],
['MA', 'Maranhão'],
@Marceloromeugoncalves
Marceloromeugoncalves / read_json.py
Created October 20, 2021 11:25
Lendo dados de um arquivo JSON com Python.
import json
with open('posts.json') as f:
posts_json = json.load(f)
for post in posts_json:
title = post['title']
content = post['content']
author_id = post['user_id']
@Marceloromeugoncalves
Marceloromeugoncalves / model.py
Created October 20, 2021 00:52
Redimensionando uma imagem ao salvar um model no Django.
#models.py
from django.db import models
from django.contrib.auth.models import User
from PIL import Image
class Profile(models.Model):
user = models.OneToOneField(User, on_delete=models.CASCADE)
image = models.ImageField(default='default.jpg', upload_to='profile_pics')
@Marceloromeugoncalves
Marceloromeugoncalves / forms.py
Created October 20, 2021 00:50
Exemplo - Estendendo o UserCreationForm do Django.
#forms.py
from django import forms
from django.contrib.auth.models import User
from django.contrib.auth.forms import UserCreationForm
from .models import Profile
class UserRegisterForm(UserCreationForm):
email = forms.EmailField()
@Marceloromeugoncalves
Marceloromeugoncalves / urls.py
Created October 20, 2021 00:47
Exemplo de CRUD com FBV no Django.
#urls.py
from django.urls import path
from .views import PostListView
from .views import PostDetailView
from .views import PostCreateView
from .views import PostUpdateView
from .views import PostDeleteView
from . import views