This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
const PASSPHRASE = ''; // use 'openssl rand -hex 32' to generate key, same with python | |
function encrypt(array $data): string | |
{ | |
$data_json_64 = base64_encode(json_encode($data)); | |
$secret_key = hex2bin(PASSPHRASE); | |
$iv = openssl_random_pseudo_bytes(openssl_cipher_iv_length('aes-256-gcm')); | |
$tag = ''; | |
$encrypted_64 = openssl_encrypt($data_json_64, 'aes-256-gcm', $secret_key, 0, $iv, $tag); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from collections import namedtuple | |
import pymongo | |
""" | |
(Jquery datatables v1.9&below - pymongo v3.11.0 - python v3.8 - mongodb v4.0.6 - django v2.2) | |
$('#table').dataTable({ | |
"sAjaxSource": "/route_name" // USE AJAX_SOURCE TO SWITCH TO V1.9 AUTOMATICALLY, even if you are using latest version! | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
heroku config:set $(cat .env | sed '/^$/d; /#[[:print:]]*$/d') | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# This script automatically installs a bunch of command line (Git, wget, | |
# imagemagick, ...) and GUI (Dropbox, Chrome, Skype, ...) apps on a fresh | |
# Mac. | |
# | |
# It also sets up a Python Scientific Computing environment (matplotlib, | |
# scipy, iPython Notebook, ...) | |
# | |
# Requirement: Have the XCode Command Line Tools installed (download from |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
""" | |
Django's SMTP EmailBackend doesn't support an SMTP_SSL connection necessary to interact with Amazon SES's newly announced SMTP server. We need to write a custom EmailBackend overriding the default EMailBackend's open(). Thanks to https://github.com/bancek/django-smtp-ssl for the example. | |
""" | |
--- settings.py | |
EMAIL_BACKEND = 'django.core.mail.backends.smtp.EmailBackend' | |
EMAIL_HOST = 'email-smtp.us-east-1.amazonaws.com' | |
EMAIL_PORT = 465 | |
EMAIL_HOST_USER = 'username' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class YourAdmin(ModelAdmin): | |
def changelist_view(self, request, extra_context=None): | |
ref = request.META.get('HTTP_REFERER','') | |
path = request.META.get('PATH_INFO','') | |
if not ref.split(path)[-1].startswith('?'): | |
q = request.GET.copy() | |
q['usertype'] = 'Publisher' | |
q['user_status__exact'] = 'activated' | |
request.GET = q | |
request.META['QUERY_STRING'] = request.GET.urlencode() |