Skip to content

Instantly share code, notes, and snippets.

View yoandresaav's full-sized avatar
🏠
Working from home

Yoandre Saavedra Gonzalez yoandresaav

🏠
Working from home
View GitHub Profile
autoload -Uz compinit
compinit
ZSH_THEME="powerlevel9k/powerlevel9k"
# Load Nerd Fonts with Powerlevel9k theme for Zsh
POWERLEVEL9K_MODE='nerdfont-complete'
source ~/powerlevel9k/powerlevel9k.zsh-theme
# Customise the Powerlevel9k prompts
POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(ssh dir vcs newline status)
POWERLEVEL9K_RIGHT_PROMPT_ELEMENTS=()
POWERLEVEL9K_PROMPT_ADD_NEWLINE=true
Clonar un repositorio de github
$ git clone <nombre del repo>
Listas las ramas y ver la activa
$ git branch
Crear una rama a partir de la rama actual
$ git checkout -b NombreDeLaRama
Guardar el Trabajo
In local settings.
"python.autoComplete.extraPaths": ["backend/"]
from djmoney.contrib.django_rest_framework import MoneyField
from moneyed import Money, Decimal
class MyMoneyField(MoneyField):
def to_representation(self, obj):
return {
'amount': "%f" % (obj.amount),
'currency': "%s" % (obj.currency),
}
@yoandresaav
yoandresaav / axios-catch-error.js
Created April 24, 2020 01:42 — forked from fgilio/axios-catch-error.js
Catch request errors with Axios
/*
* Handling Errors using async/await
* Has to be used inside an async function
*/
try {
const response = await axios.get('https://your.site/api/v1/bla/ble/bli');
// Success 🎉
console.log(response);
} catch (error) {
// Error 😨
full_name = serializers.SerializerMethodField('get_user_full_name')
def get_user_full_name(self, obj):
request = self.context['request']
user = request.user
name = user.first_name + " " + user.last_name
return name
# If modifying these scopes, delete the file token.pickle.
SCOPES = [
'openid',
'https://www.googleapis.com/auth/userinfo.email',
]
def get_user_info(credentials):
"""Send a request to the UserInfo API to retrieve the user's information.
user_email = get_user_info(credentials)['email']
Args:
I don't think Django queryset has a mechanism to order by a list of field value.
Option 1:
Order in Python. Keep it mind it will return a list, not a queryset anymore (inspired from this answer) and that you end up using magic strings (what if the user uses Entrées instead of Starters?):
sections = Section.objects.all()
order = ['Starters', 'Salads', 'Desserts']
order = {key: i for i, key in enumerate(order)}
ordered_sections = sorted(sections, key=lambda section: order.get(section.name, 0))
from django.contrib.admin.widgets import AdminDateWidget
class YourForm(forms.ModelForm):
from_date = forms.DateField(widget=AdminDateWidget())
add
{{ form.media }}
from django.contrib.admin.widgets import AdminDateWidget
class ContactForm(forms.Form):
def __ini__(etc):
super(etc)
self.label_suffix = '?'