Skip to content

Instantly share code, notes, and snippets.

jA0ECQMCRTFoVvAhkXn/0sCbARw2yE8YLkhoqthpR23JV48SciLiivb3nRIx/MQY
7bsNa3BOvctvkcmTDLKDaED+UjGNdXMaX2/EwRf05kpeJn4E4ONA5BYR04uIKzW4
kvpBItpjLa20ioLdFgMt/UnjnEEBzQXCQtr9+mYG/ZDKv+z71hZ2t7bV1iYA9KmD
M2JCqmp2TAYj5KTiKo+2e3b5E43g1kGjvlpW/iKu39KzqP8ReYPDF1Z0GXfZKeuf
Cy4Ji8WmL3ZHNoVfOo5tp2OLfLBZqgSOflXM5kvEVR4vjXEoRSB0ft9NZXOn/SmI
II4kz7jw/cfl9j908VGnlQjd/9lRPCn+TaZNF5HsTtoL5ItyPPxbtR3WmhIi9OJL
PiJ2PoIXLx1g3JLvv82Fx8Wr5t4uNxs+cK6BtnJDB1VdGWi9ymtk9fMJyslieVOy
pelY/Ylvt7Rb7Z/P/FkXMM5Cg2VPgENnW19Qq6g=
=ZzAW
@pmslavin
pmslavin / win_common_documents.py
Last active October 31, 2024 20:14
Python example of locating the Common Documents path on Windows using either the legacy CSIDL or Known Public Folder systems
import ctypes
import uuid
from ctypes import (
windll,
wintypes
)
# Pre-Vista CSIDL
CSIDL_COMMON_DOCUMENTS = 46
@pmslavin
pmslavin / pkupdate.py
Created July 6, 2022 09:41
Script to update Pywr documents using `pandas_kwargs` between new and old formats
import argparse
import json
import sys
def configure_args(args):
parser = argparse.ArgumentParser(
usage="%(prog)s [--remove-pandas-kwargs | --add-pandas-kwargs] <filename>",
epilog="",
description="Updates Pywr model `pandas_kwargs` syntax. A new file containing updated syntax is created."
@pmslavin
pmslavin / cholesky.cpp
Last active June 28, 2022 22:14
Quadratic regression by Cholesky
#include <vector>
#include <iostream>
#include <iomanip>
#include <numeric>
#include <cmath>
static const int PTERMS = 3;
/* Construct b vector of Ax=b */
double *build_bproduct(const std::vector<double>& xs, const std::vector<double>& ys)
@pmslavin
pmslavin / cholesky.py
Created June 28, 2022 21:48
A manual (no numpy.polyfit...) quadratic regression by Cholesky
"""
Second-degree polynomial fit of f(xseries) => yseries
by Choleskification and Ly=b, L^x=y
"""
import numpy as np
import matplotlib.pyplot as plt
"""
# Test series: y=x^2
xseries = [0, 0.5, 1.0, 1.5, 2.0, 2.5]
def atan_ts(z):
""" ___ oo (-1)^2n+1 * x^(2n+1)
atan(z) = \ --------------------
/__ n=0 2n+1
"""
a = 0
for n in range(17):
q = 2.0*n+1
a += (-1)**n * z**q / q
@pmslavin
pmslavin / font.py
Last active August 17, 2017 21:04
Bitmap glyph-to-include codec
#!/usr/bin/env python
"""
Bitmap glyph-to-include codec
..####.. ..####..
.#.##.#. .#.##.#.
##.##.## -d ##.##.##
######## => 60,90,219,255,129,66,60,0 ==> ########
#......# #......#
.#....#. .#....#.
#include <stdio.h>
#include <stdlib.h>
#include "b64.h"
const char *const base64 = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
const char pad = '=';
char *b64_encode(const unsigned char *src, size_t src_len)
{
"""
Generates full set of planet names across all galaxies
in the Elite series of games.
Original name generation algorithm by David Braben and Ian Bell.
Leestian Evil Juice also to Christian Pinder and the Oolite crew.
Usage:
$ python ./elitenames.py <galaxy>
@pmslavin
pmslavin / dcdemo.py
Created June 26, 2015 10:59
Deepcopy hook demo
import copy
class Parent(object):
def __init__(self):
self.children = []
def addChild(self, child):
self.children.append(child)