Skip to content

Instantly share code, notes, and snippets.

View ronnycoding's full-sized avatar
🇻🇪
The only way to do great work is to love what you do.

Ronny Freites ronnycoding

🇻🇪
The only way to do great work is to love what you do.
View GitHub Profile
@ronnycoding
ronnycoding / graphql_test_utils.py
Created June 7, 2020 02:45 — forked from Glyphack/graphql_test_utils.py
functions to test graphql api with python
from django.contrib.auth.models import AnonymousUser
from django.test import RequestFactory
from snapshottest.django import TestCase
from graphene.test import Client
from hackernews.schema import schema
class APITestCase(TestCase):
def setUp(self):
@ronnycoding
ronnycoding / README.md
Created May 7, 2020 05:17 — forked from eunomie/README.md
How to send containers log to ELK using gelf log driver

Send docker logs to ELK through gelf log driver

There's so many way to send logs to an elk... logspout, filebeat, journalbeat, etc.

But docker has a gelf log driver and logstash a gelf input. So here we are.

Here is a docker-compose to test a full elk with a container sending logs via gelf.

@ronnycoding
ronnycoding / PyJWT_authentication_routes.py
Created May 3, 2020 03:51
PyJWT Authentication routes Anonymous/Authenticated users
from rest_framework.decorators import api_view
from django.http import JsonResponse
from rest_framework.authtoken.views import ObtainAuthToken
from app.auth_helper.authenticator import Authenticator
class CustomAuthToken(ObtainAuthToken):
def post(self, request, *args, **kwargs):
serializer = self.serializer_class(data=request.data,
@ronnycoding
ronnycoding / utils.py
Created May 3, 2020 03:48
util function to get env variable on Django
import os
from django.core.exceptions import ImproperlyConfigured
def get_env_value(env_variable):
try:
return os.environ[env_variable]
except KeyError:
error_msg = 'Set the {} environment variable'.format(env_variable)
raise ImproperlyConfigured(error_msg)
@ronnycoding
ronnycoding / PyJWT.py
Created May 3, 2020 03:46
PyJWT example
import jwt
import datetime
from app.utils.utils import get_env_value
class Authenticator:
CHARSET = 'utf-8'
ALGORITHM = 'RS256'
TOKEN_TIME_DAYS = 15
CLAIMS = {
@ronnycoding
ronnycoding / jwtRS256.sh
Created May 2, 2020 02:39 — forked from ygotthilf/jwtRS256.sh
How to generate JWT RS256 key
ssh-keygen -t rsa -b 4096 -m PEM -f jwtRS256.key
# Don't add passphrase
openssl rsa -in jwtRS256.key -pubout -outform PEM -out jwtRS256.key.pub
cat jwtRS256.key
cat jwtRS256.key.pub
@ronnycoding
ronnycoding / hasura_authentications.py
Last active May 3, 2020 03:52
Django Authentication + Hasura
from graphql_jwt.utils import jwt_payload
from rest_framework_simplejwt.serializers import TokenObtainPairSerializer
from rest_framework_simplejwt.views import TokenObtainPairView
from rest_framework_simplejwt.authentication import JWTAuthentication, JWTTokenUserAuthentication
from rest_framework_simplejwt.models import TokenUser
from rest_framework_simplejwt.settings import api_settings
from rest_framework.decorators import api_view
@ronnycoding
ronnycoding / docker-compose.yml
Created April 10, 2020 18:37
WordPress + Docker Compose
version: '3.7'
services:
reverse_proxy:
image: traefik:v2.1
container_name: ${MY_DOMAIN}-proxy
ports:
# The HTTP port
- '80:80'
# The HTTPS port
@ronnycoding
ronnycoding / docker-compose.yml
Last active April 10, 2020 18:38
Magento 2 + Docker Compose
version: '3.7'
services:
reverse_proxy:
image: traefik:v2.1
container_name: ${MY_DOMAIN}-proxy
ports:
# The HTTP port
- '80:80'
# The HTTPS port
- '443:443'
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
# add a trailing slash to /wp-admin
RewriteRule ^([_0-9a-zA-Z-]+/)?wp-admin$ $1wp-admin/ [R=301,L]
RewriteCond %{REQUEST_FILENAME} -f [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^ - [L]
RewriteRule ^([_0-9a-zA-Z-]+/)?(wp-(content|admin|includes).*) $2 [L]
RewriteRule ^([_0-9a-zA-Z-]+/)?(.*\.php)$ $2 [L]