This file contains hidden or 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
# Put the following in shopify_app.authentication.py. This assumes we have a | |
# custom User model in shopify_app.models with a unique myshopify_domain | |
# attribute. The Shopify app API key and shared secret are imported from | |
# settings.py. | |
import datetime | |
import jwt | |
from datetime import timezone | |
from rest_framework import authentication | |
from rest_framework import exceptions |
This file contains hidden or 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
// cypress/support/hooks.js | |
// Cypress does not support listening to the fetch method | |
// Therefore, as a workaround we polyfill `fetch` with traditional XHR which | |
// are supported. See: https://github.com/cypress-io/cypress/issues/687 | |
enableFetchWorkaround() | |
// private helpers | |
function enableFetchWorkaround() { | |
let polyfill |
This file contains hidden or 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
/* Useful celery config. | |
app = Celery('tasks', | |
broker='redis://localhost:6379', | |
backend='redis://localhost:6379') | |
app.conf.update( | |
CELERY_TASK_RESULT_EXPIRES=3600, | |
CELERY_QUEUES=( | |
Queue('default', routing_key='tasks.#'), |
This file contains hidden or 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 celery import Task | |
from celery.task import task | |
from my_app.models import FailedTask | |
from django.db import models | |
@task(base=LogErrorsTask) | |
def some task(): | |
return result | |
class LogErrorsTask(Task): |
This file contains hidden or 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
import hashlib | |
import hmac | |
def validate_shopify_redirect(params, secret): | |
""" | |
Validates requests/redirects from Shopify according to the rules in | |
http://docs.shopify.com/api/tutorials/oauth | |
""" | |
hmac_param = params["hmac"] |
This file contains hidden or 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 datetime import datetime | |
def readable_time_elapsed(since): | |
""" | |
Generates a string with an informal English text representation of the | |
time that has elapsed between now and a given time. | |
Modified from some StackOverflow answer that I have lost. |
This file contains hidden or 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
SELECT table_schema "Database", | |
ROUND(SUM(data_length + index_length) / 1024 / 1024, 1) "Size in MB" | |
FROM information_schema.tables | |
GROUP BY table_schema; |