Skip to content

Instantly share code, notes, and snippets.

View samuelcolvin's full-sized avatar

Samuel Colvin samuelcolvin

View GitHub Profile
@samuelcolvin
samuelcolvin / datetime_toolbox.py
Created March 24, 2017 17:13
toolbox of useful methods for working with datetimes in python
"""
Useful utilities when working with datetimes, written for and tested with python 3.6
With other versions of python you're on your own.
(should work find with at least 3.5 though)
"""
from datetime import datetime, date, timedelta, timezone, tzinfo
def set_timezone(dt: datetime, tz: tzinfo) -> datetime:
@samuelcolvin
samuelcolvin / nunjucks-precompile
Last active August 4, 2017 10:49
nunjucks-precompile with jinja compat (modified from `v3.0.1`), see https://stackoverflow.com/a/45440732/949890
#!/usr/bin/env node
var path = require('path');
var precompile = require('nunjucks/src/precompile').precompile;
var Environment = require('nunjucks/src/environment').Environment;
var lib = require('nunjucks/src/lib');
var nunjucks = require('nunjucks');
nunjucks.installJinjaCompat();
var yargs = require('yargs')
@samuelcolvin
samuelcolvin / heroku_release_github_action.yml
Created November 3, 2020 12:32
push to heroku to deploy when you create a release in github
deploy:
needs:
- test
- lint
if: "success() && startsWith(github.ref, 'refs/tags/')"
runs-on: ubuntu-latest
env:
HEROKU_API_KEY: ${{ secrets.HEROKU_API_KEY }}
HEROKU_APP: <heroku app name>
@j4mie
j4mie / middleware.py
Created May 5, 2011 10:32
Django middleware to log the total number of queries run and query time for every request
from django.db import connection
from django.utils.log import getLogger
logger = getLogger(__name__)
class QueryCountDebugMiddleware(object):
"""
This middleware will log the number of queries run
and the total time taken for each request (with a
status code of 200). It does not currently support
@andresv
andresv / memcpyexample.c
Created August 9, 2012 09:55
memcpy example
#include <stdio.h>
#include <string.h>
#include <stdint.h> //uint8_t and friends
int main(void){
uint8_t settings[] = {0x00, 0x00, 0x00, 0x00, 0x00, 0x01}; // preamble, stx and other stuff must be defined here
char text[] = "hello world";
@samuelcolvin
samuelcolvin / pull_pull_request.py
Last active August 4, 2022 09:12
Pull from and pushing to other people's pull requests
#!/usr/bin/env python3
"""
pull from and pushing to other people's pull requests
(might require an auth key for private repos)
"""
import os
import re
import sys
import requests
@jcrist
jcrist / bench.py
Created January 31, 2022 20:58
A (naive) benchmark comparing pydantic & msgspec performance
"""
This benchmark is a modified version of the benchmark available at
https://github.com/samuelcolvin/pydantic/tree/master/benchmarks to support
benchmarking msgspec.
The benchmark measures the time to JSON encode/decode `n` random objects
matching a specific schema. It compares the time required for both
serialization _and_ schema validation.
"""
@azimidev
azimidev / disposable_email_addresses
Last active December 22, 2022 06:51
Notify me of any update
0815.ru
0815.ru0clickemail.com
0815.ry
0815.su
0845.ru
0clickemail.com
0-mail.com
0wnd.net
0wnd.org
10mail.com
@kklimonda
kklimonda / pybrowser.py
Created March 28, 2011 15:18
A minimal Gtk+/Webkit based browser in Python
import sys
from gi.repository import Gtk, Gdk, WebKit
class BrowserTab(Gtk.VBox):
def __init__(self, *args, **kwargs):
super(BrowserTab, self).__init__(*args, **kwargs)
go_button = Gtk.Button("go to...")
go_button.connect("clicked", self._load_url)
self.url_bar = Gtk.Entry()
@samuelcolvin
samuelcolvin / insert_assert.py
Last active May 10, 2023 17:45
auto-generate assert statements in pytest
"""
License: MIT
Copyright (c) 2022 Samuel Colvin.
See https://twitter.com/adriangb01/status/1573708407479189505
## Usage
Once installed just add