Skip to content

Instantly share code, notes, and snippets.

View evandempsey's full-sized avatar

Evan Dempsey evandempsey

View GitHub Profile
@evandempsey
evandempsey / shopify_app_bridge_token_django_rest_framework.py
Last active December 7, 2023 01:18
Setting up token authentication for Shopify App Bridge embedded apps in Django with Django Rest Framework
# 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
@evandempsey
evandempsey / cypress_support_hooks.js
Created March 5, 2020 12:37 — forked from yagudaev/cypress_support_hooks.js
Cypress Fetch Support Workaround - replaces fetch request with traditional XHR so cypress can track them
// 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
@evandempsey
evandempsey / celery.sh
Created October 29, 2018 18:32 — forked from amatellanes/celery.sh
Celery handy commands
/* 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.#'),
@evandempsey
evandempsey / celery_tasks_error_handling.py
Created October 23, 2018 17:45 — forked from darklow/celery_tasks_error_handling.py
Celery tasks error handling example
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):
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"]
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.
@evandempsey
evandempsey / mysql_databse_size_query.sql
Created October 14, 2018 14:48
Get size of MySQL database in MB
SELECT table_schema "Database",
ROUND(SUM(data_length + index_length) / 1024 / 1024, 1) "Size in MB"
FROM information_schema.tables
GROUP BY table_schema;