Skip to content

Instantly share code, notes, and snippets.

View Nipsuli's full-sized avatar

Niko Korvenlaita Nipsuli

View GitHub Profile
import itertools
import random
import simpy
def visitor(name, env, coffee_process, coffee_supply, mug_size, waittimes):
print("%s arriving at coffee station at %.1f" % (name, env.now))
with coffee_process.request() as req:
start = env.now
# Request coffee_supply
@bitdivine
bitdivine / weighted_stddev.sql
Last active November 7, 2022 09:41
postgres weighted standard deviation (stddev)
CREATE OR REPLACE FUNCTION weighted_stddev_state(state numeric[], val numeric, weight numeric) RETURNS numeric[3] AS
$$
BEGIN
IF weight IS NULL OR val IS NULL
THEN RETURN state;
ELSE RETURN ARRAY[state[1]+weight, state[2]+val*weight, state[3]+val^2*weight];
END IF;
END;
$$
LANGUAGE plpgsql;