Skip to content

Instantly share code, notes, and snippets.

Vinay Sajip vsajip

Block or report user

Report or block vsajip

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
from aiohttp import web
from aiohttp.web_log import AccessLogger
from asyncio import CancelledError
from contextvars import ContextVar
import asyncio
import logging
import secrets
vsajip / Args.ipynb
Created Feb 28, 2019 — forked from gbishop/Args.ipynb
Allow arguments to be passed to notebooks via URL or command line.
View Args.ipynb
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
vsajip /
Created Oct 18, 2018 — forked from rust-play/
Code shared from the Rust Playground
use std::io::{BufRead};
struct Processor<B: BufRead> {
reader: B
// If you uncomment p in ValidatorA, compilation fails because the size of
// ValidatorA can't be determined at compile time. Fair enough.
struct ValidatorA {
// p : Processor<BufRead>
vsajip /
Last active Oct 17, 2018 — forked from rust-play/
Code shared from the Rust Playground
use std::io::{self,BufRead,BufReader};
enum Utf8DecoderError<'a> {
InvalidBytes(&'a [u8]),
struct Utf8Decoder<B: BufRead> {
reader : B,
bytes_read: usize
vsajip /
Created Oct 16, 2018
CLI starter template for Python logging cookbook
import argparse
import importlib
import logging
import os
import sys
def main(args=None):
scriptname = os.path.basename(__file__)
parser = argparse.ArgumentParser(scriptname)
levels = ('DEBUG', 'INFO', 'WARNING', 'ERROR', 'CRITICAL')
vsajip /
Last active Oct 11, 2018
Logging format string validation
import os
import re
import string
import sys
_sfmt = string.Formatter()
FIELD_SPEC = re.compile(r'^(\d+|\w+)(\.\w+|\[[^]]+\])*$')
FMT_SPEC = re.compile(r'^(.?[<>=^])?[+ -]?#?0?(\d+|{\w+})?[,_]?(\.(\d+|{\w+}))?[bcdefgnosx%]?$')
View ColumnAttributeTypeMapper.cs
namespace YourNamespace
/// <summary>
/// Uses the Name value of the <see cref="ColumnAttribute"/> specified to determine
/// the association between the name of the column in the query results and the member to
/// which it will be extracted. If no column mapping is present all members are mapped as
/// usual.
/// </summary>
/// <typeparam name="T">The type of the object that this association between the mapper applies to.</typeparam>
public class ColumnAttributeTypeMapper<T> : FallbackTypeMapper
from sre_parse import Pattern, SubPattern, parse as sre_parse
from sre_compile import compile as sre_compile
from sre_constants import BRANCH, SUBPATTERN
class Scanner(object):
def __init__(self, tokens, flags=0):
subpatterns = []
pat = Pattern()
View gist:7629fec1e6750e077a947335bfa99bb0
import datetime
from django.conf import settings
from django.contrib.auth import logout
from django.contrib.auth.models import User
from django.contrib.sessions.models import Session
from django.http import HttpRequest
from django.utils.importlib import import_module
vsajip /
Created Jun 25, 2017 — forked from mziwisky/
Oauth2 Explanation


The Problem

I’m a web app that wants to allow other web apps access to my users’ information, but I want to ensure that the user says it’s ok.

The Solution

I can’t trust the other web apps, so I must interact with my users directly. I’ll let them know that the other app is trying to get their info, and ask whether they want to grant that permission. Oauth defines a way to initiate that permission verification from the other app’s site so that the user experience is smooth. If the user grants permission, I issue an AuthToken to the other app which it can use to make requests for that user's info.

Note on encryption

Oauth2 has nothing to do with encryption -- it relies upon SSL to keep things (like the client app’s shared_secret) secure.

You can’t perform that action at this time.