Skip to content

Instantly share code, notes, and snippets.

@johnhw
johnhw / umap_sparse.py
Last active January 6, 2024 16:09
1 million prime UMAP layout
### JHW 2018
import numpy as np
import umap
# This code from the excellent module at:
# https://stackoverflow.com/questions/4643647/fast-prime-factorization-module
import random
@posener
posener / go-shebang-story.md
Last active March 29, 2024 08:38
Story: Writing Scripts with Go

Story: Writing Scripts with Go

This is a story about how I tried to use Go for scripting. In this story, I’ll discuss the need for a Go script, how we would expect it to behave and the possible implementations; During the discussion I’ll deep dive to scripts, shells, and shebangs. Finally, we’ll discuss solutions that will make Go scripts work.

Why Go is good for scripting?

While python and bash are popular scripting languages, C, C++ and Java are not used for scripts at all, and some languages are somewhere in between.

@h4
h4 / env.py
Last active March 13, 2024 07:22
Setup alembic to work properly with PostgreSQL schemas
from __future__ import with_statement
from alembic import context
from sqlalchemy import engine_from_config, pool
from logging.config import fileConfig
from models import Base
config = context.config
fileConfig(config.config_file_name)
@karpathy
karpathy / nes.py
Last active October 23, 2023 17:50
Natural Evolution Strategies (NES) toy example that optimizes a quadratic function
"""
A bare bones examples of optimizing a black-box function (f) using
Natural Evolution Strategies (NES), where the parameter distribution is a
gaussian of fixed standard deviation.
"""
import numpy as np
np.random.seed(0)
# the function we want to optimize
@kylemcdonald
kylemcdonald / t-SNE Implementation Comparison.ipynb
Last active December 20, 2017 01:47
Comparison of different t-SNE implementations for speed and results.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@karpathy
karpathy / pg-pong.py
Created May 30, 2016 22:50
Training a Neural Network ATARI Pong agent with Policy Gradients from raw pixels
""" Trains an agent with (stochastic) Policy Gradients on Pong. Uses OpenAI Gym. """
import numpy as np
import cPickle as pickle
import gym
# hyperparameters
H = 200 # number of hidden layer neurons
batch_size = 10 # every how many episodes to do a param update?
learning_rate = 1e-4
gamma = 0.99 # discount factor for reward
FROM python:2.7-alpine
MAINTAINER Nick Janetakis <nick.janetakis@gmail.com>
ENV INSTALL_PATH /bsawf
RUN mkdir -p $INSTALL_PATH
WORKDIR $INSTALL_PATH
COPY requirements.txt requirements.txt
RUN apk add --no-cache --virtual .build-deps \
@bellbind
bellbind / laprimavera.rb
Last active May 1, 2017 17:06
[sonic-pi]vivaldi - la Primavera
# La Primavera (Vivaldi)
# Scale: Just Intornation
# E major (E=1, B=3/2, Gs=5/4, Fs=9/8, Ds=15/8, A=4/3, Cs=5/3)
def mult(n, m)
hz_to_midi(midi_to_hz(n) * m)
end
#jE5 = mult(:A5, 3.0/4)
jE5 = mult(:C5, 5.0/4)
jiscale = {
@rstuven
rstuven / decorate.coffee
Last active July 12, 2017 23:15
Decorators in CoffeeScript
###
`decorate` can apply decorators using the API proposed in
https://github.com/wycats/javascript-decorators
which is supported in Babel 5+ and TypeScript 1.5
Usage:
Foo = decorate F("color"), G, class Foo