Skip to content

Instantly share code, notes, and snippets.

View aryaniyaps's full-sized avatar
🎯
Focusing

Aryan Iyappan aryaniyaps

🎯
Focusing
View GitHub Profile
@ferndot
ferndot / emails.py
Created October 31, 2018 14:26
django-simple-email-confirmation-drf
from django.conf import settings
from templated_mail.mail import BaseEmailMessage
class VerificationEmail(BaseEmailMessage):
template_name = 'email/email_verification.html'
def get_context_data(self):
# Get context and user
@dmpayton
dmpayton / django-websockets.py
Created December 4, 2014 08:41
Django WebSockets example using Tornado
#!/usr/bin/env python
import tornado.httpserver
import tornado.ioloop
import tornado.web
import tornado.websocket
import tornado.wsgi
from myapp.wsgi import application as myapp_wsgi
# Javascript Usage:
@whoisryosuke
whoisryosuke / nextjs-hoc-authorization-ssr.js
Created August 8, 2018 22:34
NextJS - (better) HOC for authenticating pages using JWT token stored in cookies. HOC checks for cookie, if it doesn't exist, user is redirected using res or Router (ideally also query API to verify token). Wrapped in an optional context provider to pass JWT down.
import React, {Component} from 'react'
import Router from 'next/router'
import TokenContext from '../context/TokenContext'
import { getCookie } from '../utils/Cookies'
import ServerRedirect from 'utils/ServerRedirect'
export default function withAuth(AuthComponent) {
return class Authenticated extends Component {
static async getInitialProps(ctx) {
@zzzeek
zzzeek / gist:8443477
Last active January 27, 2022 03:18
expands upon the SQLAlchemy "test rollback fixure" at http://docs.sqlalchemy.org/en/rel_0_9/orm/session.html#joining-a-session-into-an-external-transaction to also support tests that have any combination of ROLLBACK/COMMIT within them, by ensuring that the Session always runs transactions inside of a savepoint.
from sqlalchemy import Column, Integer, create_engine
from sqlalchemy.ext.declarative import declarative_base
Base = declarative_base()
# a model
class Thing(Base):
__tablename__ = 'thing'
id = Column(Integer, primary_key=True)
@adunkman
adunkman / index.html
Created January 14, 2012 15:28
Relay messages from RabbitMQ to a browser using Socket.io
<!DOCTYPE html>
<html>
<head>
<script src="/socket.io/socket.io.js"></script>
<script>
(function () {
var onMessage = function (data) {
// Do something with the message data
};
@ThirVondukr
ThirVondukr / main.py
Last active March 14, 2022 11:50
Strawberry GraphQL Cursor Pagination
import base64
import enum
from typing import Any, Optional, Annotated
from sqlalchemy import select
from sqlalchemy.ext.asyncio import AsyncSession
from sqlalchemy.orm import InstrumentedAttribute, DeclarativeMeta
from sqlalchemy.sql import Select
from gql.modules.users._fields import UserOrder
"""
- Add some settings -
Log in to your sandbox account and get your API keys plus your merchant ID.
"""
BRAINTREE_PRODUCTION = False # We'll need this later to switch between the sandbox and live account
BRAINTREE_MERCHANT_ID = “your_merchant_id”
BRAINTREE_PUBLIC_KEY = “your_public_key”
BRAINTREE_PRIVATE_KEY = “your_private_key”
@pgjones
pgjones / test_flask_cookie.py
Created February 12, 2017 16:00
Example of how to use the Flask `test_request_context` with a cookie set
@parhammmm
parhammmm / fields.py
Created September 9, 2012 15:41
Custom django field for storing hex colours
import re
from django import forms
from django.db import models
class ColourFormField(forms.IntegerField):
default_error_messages = {
'invalid': 'Enter a valid colour value: e.g. "#ff0022"',
}
def __init__(self, *args, **kwargs):
@iMerica
iMerica / urls.py
Last active July 27, 2023 17:20
Email verification in Django Rest Framework, Django All-Auth, Django Rest-Auth. Suitable for Single Page Applications
urlpatterns = [
url(r'^rest-auth/registration/account-confirm-email/(?P<key>[-:\w]+)/$', ConfirmEmailView.as_view(), name='account_confirm_email'),
]