Skip to content

Instantly share code, notes, and snippets.

View araffin's full-sized avatar

Antonin RAFFIN araffin

View GitHub Profile
import matplotlib.pyplot as plt
import numpy as np
import seaborn as sns
from gymnasium import spaces
from stable_baselines3 import PPO
from stable_baselines3.common.env_util import make_vec_env
from stable_baselines3.common.vec_env import VecEnvWrapper
sns.set_theme()
@karpathy
karpathy / add_to_zshrc.sh
Created August 25, 2024 20:43
Git Commit Message AI
# -----------------------------------------------------------------------------
# AI-powered Git Commit Function
# Copy paste this gist into your ~/.bashrc or ~/.zshrc to gain the `gcm` command. It:
# 1) gets the current staged changed diff
# 2) sends them to an LLM to write the git commit message
# 3) allows you to easily accept, edit, regenerate, cancel
# But - just read and edit the code however you like
# the `llm` CLI util is awesome, can get it here: https://llm.datasette.io/en/stable/
gcm() {
@araffin
araffin / halfcheetah_minimal.py
Last active September 10, 2024 12:48
Minimal implementation to solve the HalfCheetah env using open-loop oscillators
import gymnasium as gym
import numpy as np
from gymnasium.envs.mujoco.mujoco_env import MujocoEnv
# Env initialization
env = gym.make("HalfCheetah-v4", render_mode="human")
# Wrap to have reward statistics
env = gym.wrappers.RecordEpisodeStatistics(env)
mujoco_env = env.unwrapped
n_joints = 6
import gymnasium as gym
import numpy as np
from gymnasium.envs.mujoco.mujoco_env import MujocoEnv
# Env initialization
env = gym.make("Swimmer-v4", render_mode="human")
# Wrap to have reward statistics
env = gym.wrappers.RecordEpisodeStatistics(env)
mujoco_env = env.unwrapped
n_joints = 2
@nmwsharp
nmwsharp / printarr
Last active August 15, 2024 01:43
Pretty print tables summarizing properties of tensor arrays in numpy, pytorch, jax, etc. --- now on pip: `pip install arrgh`
Pretty print tables summarizing properties of tensor arrays in numpy, pytorch, jax, etc.
Now on pip! `pip install arrgh` https://github.com/nmwsharp/arrgh
import urllib.request
from datetime import datetime
import wandb
import yaml
from yaml.loader import SafeLoader
atari_ids = [
# "AdventureNoFrameskip-v4",
# "AirRaidNoFrameskip-v4",
@Starbuck5
Starbuck5 / ascii_video_player.py
Created April 10, 2022 10:03
ASCII Video Player
import cv2
import pygame
import numpy
import functools
# WHAT IS THIS?
# This script is a simple ascii video player made in Python / pygame
# It allows you to drop in videos, or to use the webcam
pygame.init()
@Miffyli
Miffyli / assign-credits.py
Last active September 16, 2022 17:28
A very useful script for making sure everyone is credited accordingly
# A very useful script for giving credit where it is due: by replacing (most) variable names by the authors who wrote them.
# Requirements: pip install gitpython
# Usage: python3 assign-credits.py <input_file> <output_file>
# Example: python3 assign-credits.py ./src/main.py ./src/main-credited.py
# NOTE that this is an awful idea with an awful implementation. The "generated" code likely does not work
# (e.g. typing stuff is skipped, class attribute names are replaced). The "author" is decided by the current HEAD of git repo, and whoever
# defines the variable first will get the credits (hahaa dunno if even this is right).
# It is getting late and I am tired of typing so I will let Github Copilot write something for me.
@mike10004
mike10004 / inject.py
Created November 1, 2018 14:47
David Buchanan's JPEG injection code
#!/usr/bin/python3
"""
WARNING: The code you are about to view is DISGUSTING
I wrote most of it months ago, so don't ask me what it's doing, or why.
"""
import struct
import sys
@InnovArul
InnovArul / tied_linear.py
Last active January 6, 2025 23:27
tied linear layer experiment
import torch, torch.nn as nn, torch.nn.functional as F
import numpy as np
import torch.optim as optim
# tied autoencoder using off the shelf nn modules
class TiedAutoEncoderOffTheShelf(nn.Module):
def __init__(self, inp, out, weight):
super().__init__()
self.encoder = nn.Linear(inp, out, bias=False)
self.decoder = nn.Linear(out, inp, bias=False)