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
void Main(string[] args)
{
Sorvete s = new Sorvete();
Console.WriteLine("Sorvete:");
Console.WriteLine("{0:c}", s.Preco);
Console.WriteLine();
SorveteComCobertura c;
@Marceloromeugoncalves
Marceloromeugoncalves / main.py
Created March 30, 2021 22:57
Inerir dados de um arquivo CSV em um banco de dados MySQL com Python.
import csv
import MySQLdb
mydb = MySQLdb.connect(host='127.0.0.1', user='root', password='', database='all_db')
with open('cars.csv') as csv_file:
csvfile = csv.reader(csv_file, delimiter=',')
all_value = []
for row in csvfile:
value = (row[0], row[1], row[2])
@Marceloromeugoncalves
Marceloromeugoncalves / views.py
Created July 7, 2021 14:57
Renderizando um template como uma string.
from django.http import HttpResponse
from django.template.loader import render_to_string
def index(request):
t = render_to_string("blog/template.html")
return HttpResponse(t)
@Marceloromeugoncalves
Marceloromeugoncalves / base.html
Created July 27, 2021 21:39
Arquivo base.html com CDN para o CSS e JS do jQuery DataTable.
<!doctype html>
<html lang="en">
<head>
<!-- Required meta tags -->
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<!-- Bootstrap CSS -->
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap@4.5.3/dist/css/bootstrap.min.css" integrity="sha384-TX8t27EcRE3e/ihU7zmQxVncDAy5uIKz4rEkgIXeMed4M0jlfIDPvg6uqKI2xXr2" crossorigin="anonymous">
@Marceloromeugoncalves
Marceloromeugoncalves / Funcao.cs
Last active October 20, 2021 00:56
Verificar se um form já está aberto.
//Abordagem mais legível.
public static bool FormIsOpen(string formName)
{
bool formIsOpen = Application.OpenForms.Cast<Form>().Any(form => form.Name == formName);
return formIsOpen;
}
//Utilizando Array Function.
@Marceloromeugoncalves
Marceloromeugoncalves / codigos.cs
Last active October 20, 2021 00:56
Exemplo de utilização do MySQL e EF Core no ASP.NET Core.
//Pacote necessário para trabalhar com EF e MySQL.
//MySql.EntityFrameworkCore
//Pacote necessário para trabalhar com Migrations.
//Microsoft.EntityFrameworkCore.Tools
public class MyDbContext: DbContext {
//Construtor.
public MyDbContext(DbContextOptions < MyDbContext > options): base(options) {}
#Django Automatic CRUD.
#Instalação: pip install django-automatic-crud
#Verificação das dependências: pip freeze.
"""
asgiref==3.4.1
Django==3.2.7
django-automatic-crud==1.2.0
@Marceloromeugoncalves
Marceloromeugoncalves / exemplos.py
Created September 23, 2021 19:08
Exemplos Pandas DataFrame.
# Useful Pandas Snippets.
# Data Types and Conversion.
# Convert Series datatype to numeric (will error if column has non-numeric values)
pd.to_numeric(df['Column Name'])
# Convert Series datatype to numeric, changing non-numeric values to NaN.
pd.to_numeric(df['Column Name'], errors='coerce)
@Marceloromeugoncalves
Marceloromeugoncalves / exemplo_command_django.py
Created September 23, 2021 21:03
Exemplo de criação de um command com Django, para ser executado com o comando python manage.py.
"""
polls/
__init__.py
models.py
management/
__init__.py
commands/
__init__.py
_private.py
closepoll.py
@Marceloromeugoncalves
Marceloromeugoncalves / example1.py
Last active October 20, 2021 00:54
Raising a 404 error - Django
#Raising a 404 error
#polls/views.py
from django.http import Http404
from django.shortcuts import render
from .models import Question
#...