Skip to content

Instantly share code, notes, and snippets.


Vinay Sajip vsajip

View GitHub Profile
vsajip /
Created Nov 27, 2019 — forked from mastbaum/
Example of a custom ReST directive in Python docutils
'''Example of a custom ReST directive in Python docutils'''
import docutils.core
from docutils.nodes import TextElement, Inline
from docutils.parsers.rst import Directive, directives
from docutils.writers.html4css1 import Writer, HTMLTranslator
class foo(Inline, TextElement):
'''This node class is a no-op -- just a fun way to define some parameters.
There are lots of base classes to choose from in `docutils.nodes`.
import datetime
import logging
import random
import sys
import time
# Deal with minor differences between PySide2 and PyQt5
from PySide2 import QtCore, QtGui, QtWidgets
Signal = QtCore.Signal
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()