Skip to content

Instantly share code, notes, and snippets.

View thiagoferreiraw's full-sized avatar

Thiago Ferreira thiagoferreiraw

View GitHub Profile
@thiagoferreiraw
thiagoferreiraw / App.js
Last active November 9, 2018 12:05
React Tests - Medium
import React, { Component } from 'react';
import PropTypes from "prop-types"
import Home from "./Home"
const fakeDatabase = {
"Heisenberg": [
"8am - Chemistry classes at school",
"12:30pm - Meet Jesse for lunch",
"15pm - Meet Gus at the Pollos Hermanos",
"20pm - Dinner by the pool with Hank and Marie"
@thiagoferreiraw
thiagoferreiraw / App.test.js
Last active November 13, 2018 10:48
React tests - Medium - App.test com enzyme
import React from 'react';
import App from './App';
import { mount } from 'enzyme';
import toJson from "enzyme-to-json"
import Home from './Home';
it("should render the homepage for the non logged in user", () => {
const props = {
isLoggedIn: false,
username: null
@thiagoferreiraw
thiagoferreiraw / Home.js
Created November 12, 2018 16:14
Home.js
import React from 'react';
import PropTypes from "prop-types"
const Home = ({ username, tasks }) => (
<div>
<p>Welcome, {username}!</p>
<ul>
{tasks && tasks.map((t, idx) => <li key={idx}>{t}</li>)}
</ul>
</div>
@thiagoferreiraw
thiagoferreiraw / App.test.js
Created November 13, 2018 10:20
App.test.js - Com snapshot
import React from 'react';
import App from './App';
import { mount } from 'enzyme';
import toJson from "enzyme-to-json"
it("should render the homepage for the non logged in user", () => {
const props = {
isLoggedIn: false,
username: null
}
@thiagoferreiraw
thiagoferreiraw / models-1.py
Last active September 1, 2021 13:21
Medium - Metabase + Django
class ReportEngine(BaseModel, models.Model):
id = HashedAutoField(primary_key=True)
name = models.CharField(max_length=250)
type = models.CharField(
choices=(("metabase", "Metabase"),), default="metabase", max_length=50
)
base_url = models.URLField()
integration_api_key = models.CharField(max_length=250)
class EmbeddedReport(BaseModel, models.Model):
@thiagoferreiraw
thiagoferreiraw / models-2.py
Last active November 8, 2021 11:49
Medium - Metabase + Django - 2
class EmbeddedReport(BaseModel, models.Model):
...
...
...
def get_report_url_for_business(self, business)
map_resource = {
"dashboard": {
"params": {"dashboard": int(self.reference_id)},
"url_path": "dashboard",
},
@thiagoferreiraw
thiagoferreiraw / 1-views.py
Last active September 1, 2021 13:23
Medium - Metabase + Django - 3
class EmbeddedReportResource(PaginatorMixin, APIResource):
preparer = EMBEDDED_REPORT_LIST_PREPARER
paginate = True
page_size = 40
@property
def base_query(self):
return (
EmbeddedReport.objects.filter(active=True)
.select_related("engine")
@thiagoferreiraw
thiagoferreiraw / git-revert.sh
Created September 9, 2021 19:36
Giit Revert
# Escolha sua branch de origem, de onde os commits serão revertidos
git checkout main
# Use o commando git revert com a opção "-n" pra gerar um único commit
# Os ids abaixo podem ser encontrados usando o `git log`
git revert -n f21306c..e330c04 # OLD_COMMIT..RECENT_COMMIT
# Nesse ponto, você já pode usar os comandos de status e diff pra conferir se a alteração está correta:
git status # mostra os nomes dos arquivos alterados
git diff # mostra as mudanças efetivas
@thiagoferreiraw
thiagoferreiraw / git-diff-apply.sh
Created September 9, 2021 19:45
Git Diff + git apply
# Escolha sua branch de origem, de onde os commits serão revertidos
git checkout main
# Usando o git log, encontre o hash do commit do ponto que você deseja retornar para.
git checkout f21306c
# Agora vamos fazer uma comparação entre a posição atual do histórico e a main.
# Nesse ponto precisamos confirmar se as mudanças exibidas aqui estão corretas ;)
# Se não estiverem, você provavelmente está no ponto errado do histórico (veja o git log)
git diff main
@thiagoferreiraw
thiagoferreiraw / locust.py
Created November 4, 2021 12:27
Python Locust
import lorem
from locust import HttpUser, task, between
class WebsiteUser(HttpUser):
wait_time = between(1, 3)
@task(5)
def index(self):
self.client.get("/tasks/")