Skip to content

Instantly share code, notes, and snippets.

@cheldernunes
cheldernunes / admin.py
Created October 5, 2018 18:58
This gist show how remove add link in related fields in admin django. Replace field_name with your field.
@admin.register(ModelName)
class CustomAdmin(admin.ModelAdmin):
def formfield_for_dbfield(self, db_field, **kwargs):
formfield = super().formfield_for_dbfield(db_field, **kwargs)
if db_field.name == "field_name":
formfield.widget.can_add_related = False
return formfield
@cheldernunes
cheldernunes / phone_validator_django.py
Created October 12, 2018 00:20
Django RegexValidator for phone numbers with ddd+number(8 or 9) digits
# brazil's code areas
# http://www.anatel.gov.br/setorregulado/codigos-nacionais/codigos-nacionais
# http://www.anatel.gov.br/legislacao/resolucoes/16-2001/383-resolucao-263
phone_validator = RegexValidator(regex=r'^(1[1-9]|2[1-2,4,7,8]|3[1-5]|3[7-8]|4[1-9]'
r'|5[1,3-5]|6[1-9]|7[1,3,4,5,7,9]'
r'|8[1-9]|9[1-9]){1}[0-9]{8,9}$',
message="Phone number must be entered in the format '99000000000'. "
"where 99(2 digits) is a brazil code area, and 000000000 is a number phone "
"with 8 or 9 digits.")
@cheldernunes
cheldernunes / bash.sh
Created March 11, 2019 21:52
Gerar SSH Key public
cd ~/.ssh
ssh-keygen -t rsa -b 4096 -C "dev@email.com"
eval "$(ssh-agent -s)"
ssh-add ~/.ssh/id_rsa
cat ~/.ssh/id_rsa.pub
@cheldernunes
cheldernunes / single.sh
Created May 20, 2019 13:04
print private key in single line
awk 'NF {sub(/\r/, ""); printf "%s\\n",$0;}' ca.pem
@cheldernunes
cheldernunes / git.sh
Created August 8, 2019 17:51
discard local changes in git pull
git reset --hard && git pull
@cheldernunes
cheldernunes / translate.md
Last active October 18, 2019 18:01
internacionalization django
  • To update .po translate file run python manage.py makemessages -l=pt_BR;
  • Run python manage.py compilemessages to compile the translations (pt-br only);
@cheldernunes
cheldernunes / out.py
Last active October 24, 2019 11:09
Print pretty json out with python
print(json.dumps({"key": "value"}, indent=4, sort_keys=True))
@cheldernunes
cheldernunes / ba.sh
Created October 30, 2019 01:09
ban IP with fail2bah
fail2ban-client -vvvv set wordpress banip 129.213.67.237
@cheldernunes
cheldernunes / run.sh
Created December 26, 2019 12:49
Fix webcam stopped in macbook pro
/*
* Run in terminal of OSX
*/
sudo killall VDCAssistant