Skip to content

Instantly share code, notes, and snippets.

View klebercode's full-sized avatar
🚴
Go...

Kleber Soares klebercode

🚴
Go...
View GitHub Profile
@klebercode
klebercode / upgrade.md
Created May 15, 2018 14:55 — forked from zulhfreelancer/upgrade.md
How to upgrade Heroku Postgres database plan?
  1. Assuming you have multiple Heroku apps and Git remote like so:
development https://git.heroku.com/xxx.git (fetch)
development https://git.heroku.com/xxx.git (push)
origin      git@bitbucket.org:xxx/xxx.git  (fetch)
origin      git@bitbucket.org:xxx/xxx.git  (push)
production  https://git.heroku.com/xxx.git (fetch)
production  https://git.heroku.com/xxx.git (push)
staging https://git.heroku.com/xxx.git (fetch)
@klebercode
klebercode / urls.py
Created September 27, 2018 00:04 — forked from duffn/urls.py
django-graphene JWT authorization
# Authorization with django-graphene
# using django-jwt-auth==0.0.2
from django.conf.urls import url
from django.views.decorators.csrf import csrf_exempt
from graphene_django.views import GraphQLView
from jwt_auth.mixins import JSONWebTokenAuthMixin
class AuthGraphQLView(JSONWebTokenAuthMixin, GraphQLView):
@klebercode
klebercode / 01_utils.py
Created September 28, 2018 17:25 — forked from mbrochh/01_utils.py
Using pagination with Django, graphene and Apollo
from django.core.paginator import EmptyPage, PageNotAnInteger, Paginator
# First we create a little helper function, becase we will potentially have many PaginatedTypes
# and we will potentially want to turn many querysets into paginated results:
def get_paginator(qs, page_size, page, paginated_type, **kwargs):
p = Paginator(qs, page_size)
try:
page_obj = p.page(page)
except PageNotAnInteger:
from graphene import relay, String, List
from graphene_django.filter import DjangoFilterConnectionField
from graphene_django.fields import DjangoConnectionField
from app.models import Model
class Object(DjangoObjectType):
class Meta:
model = Model
@klebercode
klebercode / iterm2-solarized.md
Created November 27, 2018 22:54 — forked from kevin-smets/iterm2-solarized.md
iTerm2 + Oh My Zsh + Solarized color scheme + Meslo powerline font + [Powerlevel9k] - (macOS)

Default

Default

Powerlevel9k

Powerlevel9k

@klebercode
klebercode / actions.py
Created February 8, 2019 01:30 — forked from ahmontero/actions.py
Trace the changes made to a django model. You can see how to use it in example.py
# -*- encoding: utf-8 -*-
# --------------------------
# Ripped from django project
# --------------------------
from django.contrib.contenttypes.models import ContentType
from django.utils.translation import ugettext as _
from django.utils.encoding import force_unicode
@klebercode
klebercode / admin.py
Created April 25, 2019 00:01 — forked from hakib/admin.py
How to Turn Django Admin Into a Lightweight Dashboard
# https://hakibenita.com/how-to-turn-django-admin-into-a-lightweight-dashboard
from django.contrib import admin
from django.db.models import Count, Sum, Min, Max, DateTimeField)
from django.db.models.functions import Trunc
from . import models
def get_next_in_date_hierarchy(request, date_hierarchy):

tmux cheatsheet

As configured in my dotfiles.

start new:

tmux

start new with session name:

remember_me = forms.BooleanField(required=False, widget=forms.CheckboxInput())
if not self.cleaned_data.get('remember_me'):
self.request.session.set_expiry(0)
@klebercode
klebercode / 00_GraphQL_Subscriptions.md
Created September 23, 2019 15:18 — forked from tricoder42/00_GraphQL_Subscriptions.md
GraphQL Subscriptions with django-channels

GraphQL Subscription with django-channels

Django channels are official way for implementing async messaging in Django.

The primary caveat when working with GraphQL subscription is that we can't serialize message before broadcasting it to Group of subscribers. Each subscriber might use different GraphQL query so we don't know how to serialize instance in advance.

See related issue