Skip to content

Instantly share code, notes, and snippets.

@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]
@pmslavin
pmslavin / fancy-tabs-demo.html
Created August 17, 2021 17:58 — forked from ebidel/fancy-tabs-demo.html
Fancy tabs web component - shadow dom v1, custom elements v1, full a11y
<script>
function execPolyfill() {
(function(){
// CustomElementsV1.min.js v1 polyfill from https://github.com/webcomponents/webcomponentsjs/tree/v1/src/CustomElements/v1.
/*
Copyright (c) 2016 The Polymer Project Authors. All rights reserved.
This code may only be used under the BSD style license found at http://polymer.github.io/LICENSE.txt
The complete set of authors may be found at http://polymer.github.io/AUTHORS.txt
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)
@pmslavin
pmslavin / sdl2_opengl.c
Last active December 27, 2015 14:49 — forked from exavolt/sdl2_opengl.c
/*
Fixed out-of-scope SDL_Renderer*. Now compiles with
$CC sdl2_opengl.c -o sdl2_opengl -lSDL2 -lGL -lGLU
*/
#include <stdlib.h>
#include <stdio.h>
#include <string.h>