Skip to content

Instantly share code, notes, and snippets.

View vsajip's full-sized avatar

Vinay Sajip vsajip

View GitHub Profile
from ctypes import *
from ctypes.wintypes import (HANDLE, ULONG, DWORD, BOOL, LPCSTR, LPCWSTR, WORD,
USHORT)
import msvcrt
import platform
import sys
#------------------------------------------------------------------------------
# WinSock2 definitions
#------------------------------------------------------------------------------
@vsajip
vsajip / build.gradle.kts
Created November 29, 2019 17:05
A build.gradle.kts
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
plugins {
java
kotlin("jvm") version "1.3.61"
kotlin("kapt") version "1.3.61"
}
version = "0.1-SNAPSHOT"
@vsajip
vsajip / custom_directive.py
Created November 27, 2019 15:36 — forked from mastbaum/custom_directive.py
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
try:
from PySide2 import QtCore, QtGui, QtWidgets
Signal = QtCore.Signal
# 05_aiohttp.py
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
vsajip / Args.ipynb
Created February 28, 2019 09:51 — forked from gbishop/Args.ipynb
Allow arguments to be passed to notebooks via URL or command line.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@vsajip
vsajip / playground_02.rs
Created October 18, 2018 08:30 — forked from rust-play/playground.rs
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
vsajip / playground_01.rs
Last active October 17, 2018 08:37 — forked from rust-play/playground.rs
Code shared from the Rust Playground
use std::io::{self,BufRead,BufReader};
enum Utf8DecoderError<'a> {
InvalidBytes(&'a [u8]),
Io(io::Error),
}
struct Utf8Decoder<B: BufRead> {
reader : B,
bytes_read: usize
@vsajip
vsajip / app.py
Created October 16, 2018 11:13
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
vsajip / fmt_test.py
Last active October 11, 2018 08:12
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%]?$')