Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # Could not open a connection to your authentication agent
- eval `ssh-agent -s`
- # ssh remote port forwarding
- ```shell
- ssh -nNT -L 9000:ifconfig.me:80 mords
- ```
- # django import config
- ```python
- from django.conf import settings
- if settings.DEBUG:
- # Do something
- ```
- # python strftime
- # python strptime
- # django send mail
- In two lines:
- ```python
- from django.core.mail import send_mail
- send_mail(
- 'Subject here',
- 'Here is the message.',
- 'from@example.com',
- ['to@example.com'],
- fail_silently=False,
- )
- ```
- ```
- EMAIL_BACKEND = 'django.core.mail.backends.smtp.EmailBackend'
- EMAIL_HOST = 'smtp.exmail.qq.com'
- EMAIL_HOST_USER = 'sys@yourdomain.com'
- EMAIL_HOST_PASSWORD = 'youpass'
- EMAIL_TIMEOUT = 10
- ```
- # django field lookup
- isnull
- Takes either True or False, which correspond to SQL queries of IS NULL and IS NOT NULL, respectively.
- ```python
- Entry.objects.filter(pub_date__isnull=True)
- ```
- ```SQL
- SELECT ... WHERE pub_date IS NULL;
- ```
- # django annotate
- ```python
- from django.db.models import Sum
- Title.objects.values('publisher').annotate(tot_dbl_prices=2*Sum('price'))
- ```
- # python defaultdict
- ```python
- from collections import defaultdict
- s = [('yellow', 1), ('blue', 2), ('yellow', 3), ('blue', 4), ('red', 1)]
- d = defaultdict(list)
- for k, v in s:
- d[k].append(v)
- d.items()
- [('blue', [2, 4]), ('red', [1]), ('yellow', [1, 3])]
- ```
- # mysql create user and grant permission
- ```sql
- CREATE USER 'newuser'@'localhost' IDENTIFIED BY 'password';
- GRANT type_of_permission ON database_name.table_name TO ‘username’@'localhost’;
- GRANT ALL PRIVILEGES ON * . * TO 'newuser'@'localhost';
- ```
Add Comment
Please, Sign In to add comment