READ pallets/flask#1938
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import numpy as np | |
import matplotlib.pyplot as plt | |
import pygame | |
from scipy.io.wavfile import write | |
import time | |
import threading | |
import sys | |
import cmd | |
import os |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Agent: | |
def __init__(self, name, ports=None): | |
self.name = name | |
self.ports = ports if ports else [] | |
# Each element of ports is either None or a tuple (other_agent, other_port_index) | |
def __repr__(self): | |
return f"{self.name}" | |
def connect(a, pa, b, pb): |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Rezero(layers.Layer): | |
def __init__(self): | |
super().__init__() | |
self.alpha1 = tf.Variable(0.0, trainable=True) | |
def call(self, inputs, training): | |
return self.alpha1*inputs | |
class CustomRezero(tf.keras.layers.Layer): |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function import-ts-repl() { ( | |
set -e | |
file=$1 | |
rm -f ${file}.js ${file}.js.map | |
esbuild ${file} --target=node14 --format=cjs --sourcemap --outfile=${file}.js --platform=node --bundle | |
node -r ${file}.js | |
rm -f ${file}.js ${file}.js.map | |
); } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// January 2022, Luke Harold Miles, public domain obviously | |
// Adapted from: https://github1s.com/expressjs/express/blob/master/examples/auth/index.js | |
// You can run with `ts-node express-typescript-auth.ts` | |
// Source for this file to get updates: https://gist.github.com/qpwo/4b2ae3aaaf222d099b34898152118c43 | |
import { pbkdf2Sync, randomBytes, timingSafeEqual } from 'crypto' | |
import type { NextFunction, Request, Response } from 'express' | |
import express from 'express' | |
import type { Session } from 'express-session' | |
import session from 'express-session' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
""" | |
A simple predator-prey multi-agent reinforcement learning environment in | |
python without dependencies, and an implementation of an example q-learning agent. | |
Python 3.9 | |
https://gist.github.com/qpwo/a19f43368afd77288bf3b7db81fdc18b/ | |
February, 2021 -- Public domain dedication | |
""" | |
from dataclasses import dataclass, field | |
import random |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Compile with gcc -std=c99 mersenne_twister.c -o /dev/random | |
// ps the -o /dev/random part is a joke, it's not actually meant to be a random device. | |
// Absolutely no warranty, Kopyleft I guess who gives a shit | |
#include <stdint.h> | |
#include <stdio.h> | |
uint32_t x[624]; | |
uint32_t index = 0; | |
void twist() { | |
for (int k = 0; k < 624; k++) { | |
x[k] = x[(k+397)%624] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import math | |
import scipy.stats as st | |
# assumes bivariate normal, dichotomised groups | |
def dichotomy_r_to_d(r) : | |
d = 2*r / (math.sqrt(1 - r**2)) | |
return d | |
# Equation 9 | |
# https://sci-hub.tw/10.1037/1082-989X.11.4.386 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Experiments in capturing combined output streams from subprocesses. | |
# | |
# It turns out it's kind of hard to get the interleaved results of stdout and | |
# stderr in Python. However, in a lot of situations where Python is calling | |
# out to other processes, you probably want to swallow the child process's | |
# stderr when things to right and print it when things go wrong. Since some | |
# programs may be outputting results on stdout and warnings and errors on | |
# stderr, it makes sense that you'd want it all, and all in the order it was | |
# printed when things go wrong. | |
# |
NewerOlder