Skip to content

Instantly share code, notes, and snippets.

Avatar

Vinay Sajip vsajip

View GitHub Profile
View webapplib.py
import logging
import time
logger = logging.getLogger(__name__)
def useful():
logger.debug('Hello from webapplib!')
time.sleep(0.01)
@vsajip
vsajip / typescript-web-components.md
Created Apr 25, 2020 — forked from aelbore/typescript-web-components.md
Step by Step creating web components in typescript using rollup
View typescript-web-components.md

Getting Started

  • Install Dependencies
    npm init
    npm install --save-dev ts-node typescript tslib express @types/express
    

Create your web server

  • Create server.ts in root folder of your app.
@vsajip
vsajip / overlay_pdf.py
Created Apr 11, 2020 — forked from dwayneblew/overlay_pdf.py
Overlay text on a PDF template using fpdf and PyPDF2
View overlay_pdf.py
import fpdf
from PyPDF2 import PdfFileWriter, PdfFileReader
overlay_pdf_file_name = 'overlay_PDF.pdf'
pdf_template_file_name = 'base_PDF_template.pdf'
result_pdf_file_name = 'final_PDF.pdf'
# This section creates a PDF containing the information you want to enter in the fields
# on your base PDF.
View socktest.py
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 Nov 29, 2019
A build.gradle.kts
View 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"
View queuehandler.py
import logging
class QueueHandler(logging.Handler):
"""
This handler sends events to a queue. Typically, it would be used together
with a multiprocessing Queue to centralise logging to file in one process
(in a multi-process application), so as to avoid file write contention
between processes.
This code is new in Python 3.2, but this class can be copy pasted into
@vsajip
vsajip / custom_directive.py
Created Nov 27, 2019 — forked from mastbaum/custom_directive.py
Example of a custom ReST directive in Python docutils
View custom_directive.py
'''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`.
View qtlog.py
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
View aiohttp_request_id_logging.py
# 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 / doc-watch.py
Last active Apr 8, 2019
Sphinx HTML documentation watcher
View doc-watch.py
#!/usr/bin/env python3
#
# Copyright (C) 2012 Vinay Sajip. Licensed under the MIT license.
#
# Based on Roberto Alsina's 128-line web browser, see
#
# http://lateral.netmanagers.com.ar/weblog/posts/BB948.html
#
import json
import os