Skip to content

Instantly share code, notes, and snippets.

@reinderien
reinderien / 77470565.py
Last active November 13, 2023 21:17
Probit and transforming z-scores (price optimization)
# Based on https://stackoverflow.com/questions/77470565/probit-and-transforming-z-scores-in-gurobi-price-optimization
import numpy as np
import pulp
import pandas as pd
def make_distribution() -> tuple[
np.ndarray, # z scores
pd.Series, # probabilities
@reinderien
reinderien / Flory-Huggins.py
Created August 26, 2023 17:01
Flory-Huggins
import scipy.optimize
import numpy as np
import matplotlib.pyplot as plt
def F(
phi: np.ndarray,
uaa: float, ubb: float, uab: float, na: int, nb: int,
) -> np.ndarray:
"""
"""
Based on https://stackoverflow.com/questions/76647505
"""
import pandas as pd
import pulp
data = {
'Product': ('Product 1', 'Product 2', 'Product 3', 'Product 4',
'Product 1', 'Product 2', 'Product 3', 'Product 4',
@reinderien
reinderien / demo.py
Created May 7, 2022 15:56
Generators close context managers
class SomeCtx:
def __enter__(self):
return self
def __exit__(self, exc_type, exc_val, exc_tb):
print('I exited')
from abc import ABC, abstractmethod
from contextlib import contextmanager
from dataclasses import dataclass
from os import path
from pathlib import Path
from typing import List, Dict, Optional, Any
from urllib.parse import urljoin
from bs4 import BeautifulSoup, SoupStrainer
from _decimal import Decimal
from dataclasses import dataclass
from locale import currency, setlocale, LC_ALL
from sys import stdout
from typing import Collection
TAX = Decimal(0.15)
@dataclass
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@reinderien
reinderien / kwartzlab-electronics.md
Last active January 27, 2020 15:19
KwartzLab Electronic Session with Greg

What?

This is a handful of sessions to learn various subjects in electronics, including component selection, mains safety, a little bit of embedded design and programming, prototyping, and CAD. It will be done by making a simple clock with easy-to-manipulate through-hole parts.

These sessions are to be run separately from Ryan's KiCad session because this has a different focus - electronics basics - and uses a different CAD program, Eagle, because it's what I'm familiar with. All software used is free.

Attendees are to bring their laptop, note-taking material, and a calculator if they have one. (Math will not exceed the elementary school level.) Grid paper is recommended but not necessary. Bring $20.00 in total (not per session) to cover the cost of parts. If the attendee elects to purchase fabrication, that cost will be separate.

In the lab we will be using oscilloscopes, power supplies, multimeters and prototyping parts brought in for this project.

@reinderien
reinderien / insanity.md
Created August 15, 2019 03:50
xlsxwriter and insane units

Welcome to the descent into madness that is Excel units.

xlsxwriter has this lovely nugget that, unless you really care about exact column widths, you probably never had the urge to look up:

# Convert column width from user units to character width.
# For Calabri 11.
max_digit_width = 7
@reinderien
reinderien / pfsense-11_1-openconnect.md
Last active January 26, 2018 21:21
pfSense 11.1 with OpenConnect