Skip to content

Instantly share code, notes, and snippets.

View elyssonmr's full-sized avatar
🤘

Élysson MR elyssonmr

🤘
View GitHub Profile
class X:
def __eq__(self, other):
return True
x = X()
if x == 1 and x == 2 and x == 3:
print('Absurdo')
VARIABLE_CACHE = {}
def request_data(url):
if 'my_data' not in VARIABLE_CACHE:
data = request_data_from_web(url)
VARIABLE_CACHE['my_data'] = data
return data
else:
return VARIABLE_CACHE['my-data']
class MyFormClass(forms.ModelForm):
def __init__(self, *args, **kwargs):
super()
pk = kwargs.pop("pk", None)
if pk:
self.field_with_querystring.query = Something.objects.filter(pk=pk)
form = MyFormClass(pk=client_id)
@elyssonmr
elyssonmr / locust_test.py
Created March 15, 2019 03:43
Locust test failing when the median is slower than a value. CMD: locust -f locust_test.py --no-web -c 100 -r 50 -t 10s -H http://elyssonmr.com --only-summary
from locust import stats, HttpLocust, TaskSet, task, events
from locust.runners import locust_runner
import sys
class QueryElyssonMRTaskSet(TaskSet):
@task(5)
def query_for_facebook(self):
url = ""
self.client.get(url)
@elyssonmr
elyssonmr / locust_test.py
Created March 15, 2019 03:43
Locust test failing when the median is slower than a value.
from locust import stats, HttpLocust, TaskSet, task, events
from locust.runners import locust_runner
import sys
class QueryElyssonMRTaskSet(TaskSet):
@task(5)
def query_for_facebook(self):
url = ""
self.client.get(url)
@elyssonmr
elyssonmr / algoritmo.py
Created February 5, 2019 01:06
websocket
"""
Fluxo de usuário se conectando
1. usuário vai se conectar usando o websocket
1.1. quando o usuário se conectar vamos adiciona-lo a uma lista (ou dicionado) de usuários conectados
3. Ler os ramais registrados no redis
4. Responder o usuário com a lista de Ramais.
Novo Ramal cadastrado
python teste.py
EXEC1=$?
python teste2.py
EXEC2=$?
python teste3.py
EXEC3=$?
if [ $EXEC1 -eq "1" ] || [ $EXEC2 -eq "1" ] || [ $EXEC3 -eq "1" ]
then
echo "ooohh snap :("
class VendasAdmin(admin.ModelAdmin):
list_display = ('valor_total', 'outros', 'campos')
def valor_total(self, obj):
return '%.2f' % obj.balance
@elyssonmr
elyssonmr / umongo_test.py
Created July 26, 2018 12:27
uMongo unique issue
import asyncio
from datetime import datetime
from motor.motor_asyncio import AsyncIOMotorClient
from umongo import Instance, Document, fields, validate
db = AsyncIOMotorClient().test
instance = Instance(db)
@instance.register
class User(Document):
@elyssonmr
elyssonmr / models.py
Created December 20, 2017 01:52
Estoque Simples OP of Darkness
from alguma_coisa_do_django import models
TRANSACTION_KIND = (
("in", "Entrada"),
("out", "Saida"),
("eaj", "Entrada de Ajuste"),
("saj", "Saída de Ajuste")
)