Guest User

Untitled

a guest
Apr 18th, 2018
344
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.74 KB | None | 0 0
  1. # Could not open a connection to your authentication agent
  2. eval `ssh-agent -s`
  3.  
  4. # ssh remote port forwarding
  5. ```shell
  6. ssh -nNT -L 9000:ifconfig.me:80 mords
  7. ```
  8.  
  9. # django import config
  10. ```python
  11. from django.conf import settings
  12.  
  13. if settings.DEBUG:
  14. # Do something
  15. ```
  16.  
  17. # python strftime
  18.  
  19. # python strptime
  20.  
  21. # django send mail
  22. In two lines:
  23. ```python
  24. from django.core.mail import send_mail
  25.  
  26. send_mail(
  27. 'Subject here',
  28. 'Here is the message.',
  29. 'from@example.com',
  30. ['to@example.com'],
  31. fail_silently=False,
  32. )
  33. ```
  34. ```
  35. EMAIL_BACKEND = 'django.core.mail.backends.smtp.EmailBackend'
  36. EMAIL_HOST = 'smtp.exmail.qq.com'
  37. EMAIL_HOST_USER = 'sys@yourdomain.com'
  38. EMAIL_HOST_PASSWORD = 'youpass'
  39. EMAIL_TIMEOUT = 10
  40. ```
  41.  
  42. # django field lookup
  43. isnull
  44. Takes either True or False, which correspond to SQL queries of IS NULL and IS NOT NULL, respectively.
  45. ```python
  46. Entry.objects.filter(pub_date__isnull=True)
  47. ```
  48. ```SQL
  49. SELECT ... WHERE pub_date IS NULL;
  50. ```
  51. # django annotate
  52. ```python
  53. from django.db.models import Sum
  54.  
  55. Title.objects.values('publisher').annotate(tot_dbl_prices=2*Sum('price'))
  56. ```
  57.  
  58. # python defaultdict
  59. ```python
  60. from collections import defaultdict
  61.  
  62. s = [('yellow', 1), ('blue', 2), ('yellow', 3), ('blue', 4), ('red', 1)]
  63. d = defaultdict(list)
  64. for k, v in s:
  65. d[k].append(v)
  66. d.items()
  67. [('blue', [2, 4]), ('red', [1]), ('yellow', [1, 3])]
  68. ```
  69.  
  70. # mysql create user and grant permission
  71. ```sql
  72. CREATE USER 'newuser'@'localhost' IDENTIFIED BY 'password';
  73. GRANT type_of_permission ON database_name.table_name TO ‘username’@'localhost’;
  74. GRANT ALL PRIVILEGES ON * . * TO 'newuser'@'localhost';
  75. ```
Add Comment
Please, Sign In to add comment