Skip to content

Instantly share code, notes, and snippets.

@aksh-at
aksh-at / jupyter-bore.py
Last active April 5, 2023 13:26
Jupyter on Modal through Bore
# Quick snippet to connect to a Jupyter notebook server running inside a Modal container,
# especially useful for exploring the contents of Modal shared volumes.
# This uses https://github.com/ekzhang/bore to expose the server to the public internet.
#
# Steps
# -----
# 1. (Recommended) Change `JUPYTER_TOKEN` to a different value; default is 1234.
# 2. `modal run jupyter-bore.py`
# 3. Find the `bore.pub` URL printed in the logs, and navigate to it using your browser.
@takuma104
takuma104 / diffusers_sd_xformers_flash_attention.py
Last active July 29, 2023 20:09
Generating (almost) reproducible pictures using Diffusers with xFormers
import torch
from diffusers import StableDiffusionPipeline, DPMSolverMultistepScheduler
import matplotlib.pyplot as plt
from PIL import Image
import numpy as np
plt.rcParams["figure.figsize"] = (10,5)
plt.rcParams['figure.facecolor'] = 'white'
def generate_tuxedo_cat_picture(fn_prefix, seed=0):
@jdbcode
jdbcode / get-hex-colors.py
Last active April 11, 2024 20:09
Get a list of n hex colors for a given matplotlib palette
# Source: https://stackoverflow.com/a/33597599/5391200
from pylab import *
cmap = cm.get_cmap('seismic', 5) # matplotlib color palette name, n colors
for i in range(cmap.N):
rgb = cmap(i)[:3] # will return rgba, we take only first 3 so we get rgb
print(matplotlib.colors.rgb2hex(rgb))
cmap = cm.get_cmap('plasma', 101)
from PIL import Image, ImageOps
def padding(img, expected_size):
desired_size = expected_size
delta_width = desired_size - img.size[0]
delta_height = desired_size - img.size[1]
pad_width = delta_width // 2
pad_height = delta_height // 2
padding = (pad_width, pad_height, delta_width - pad_width, delta_height - pad_height)
@artificialsoph
artificialsoph / jupyter_ngrok.md
Last active May 30, 2024 04:24
Quickest way to get Jupyter notebook running on a remote server.

Log into your server with ssh, something like

ssh -i "my_secret.pem" ubuntu@12.123.12.123

If it's a new server, you'll need to install a few things.

Install conda with

@mda590
mda590 / stress_test.py
Created June 8, 2018 14:07
Python script useful for stress testing systems
"""
Produces load on all available CPU cores.
Requires system environment var STRESS_MINS to be set.
"""
from multiprocessing import Pool
from multiprocessing import cpu_count
import time
import os
@benzap
benzap / youtube2mp3.py
Last active May 3, 2022 05:39
Youtube to MP3 Downloader Script
#!/bin/env python
# Requires: youtube_dl module
# Requires: ffmpeg
# Usage:
#
# python youtube2mp3.py <URL>, ...
#
# Example:
#
# python youtube2mp3.py https://www.youtube.com/watch?v=dQw4w9WgXcQ
@dsal1951
dsal1951 / Calculate Model Lift
Created July 4, 2016 05:53
Data needed for a Lift chart (aka Gains chart) for a predictive model created using Sklearn and Matplotlib
def calc_lift(x,y,clf,bins=10):
"""
Takes input arrays and trained SkLearn Classifier and returns a Pandas
DataFrame with the average lift generated by the model in each bin
Parameters
-------------------
x: Numpy array or Pandas Dataframe with shape = [n_samples, n_features]
y: A 1-d Numpy array or Pandas Series with shape = [n_samples]
@tgarc
tgarc / example_usage
Last active March 25, 2022 13:44
Jekyll IPython notebook converter
ipython nbconvert --to markdown <notebook>.ipynb --config jekyll.py
@magicznyleszek
magicznyleszek / css-selectors.md
Last active March 29, 2024 01:12
CSS Selectors Cheatsheet

CSS Selectors Cheatsheet

Hi! If you see an error or something is missing (like :focus-within for few years :P) please let me know ❤️

Element selectors

Element -- selects all h2 elements on the page

h2 {