Skip to content

Instantly share code, notes, and snippets.

View UlisseMini's full-sized avatar
:shipit:
doing stupid stuff in the most complicated way possible

Ulisse Mini UlisseMini

:shipit:
doing stupid stuff in the most complicated way possible
View GitHub Profile
# Run with ipython -i sympy-exact-approx.py so you can play with it afterwards
import sympy as sp
x = sp.Symbol('x')
# function to approximate, if this is exotic change inner() to compute
# integrals numerically instead of symbolically.
def f(x):
# standard example
@UlisseMini
UlisseMini / flatten-hessian-mnist.py
Last active January 9, 2023 20:37
How to obtain the hessian of an mnist neural net as a flat matrix
# fuller code https://colab.research.google.com/drive/12zXLbykv537MrZr6WDCnRIqKQ5h8UjVw?usp=sharing
fn = lambda *params: F.nll_loss(stateless.functional_call(model, {n: p for n,p in zip(names, params)}, x), y)
H = hessian(fn, tuple(model.parameters()))
# H[i][j] contains the derivatives of the loss with respect to every parameter in model.parameters()[i] and [j].
# (It's an annoying tuple)
# flatten the annoying tuple!
rows = []
shapes = [p.shape for p in model.parameters()]
N = 100
def guess(P, j):
# after setting P[j] = 0 we have removed P[j] probability mass from
# the distribution, so the new sum is 1-P[j]. Dividing everything by
# 1-P[j] fixes this. (a minor detail, instead of 1 we use sum(P) for
# numerical stability since sum(P) isn't exactly 1)
s = sum(P) - P[j]
return [
0 if i == j else P[i] / s
import matplotlib.pyplot as plt
import numpy as np
tau = 2*np.pi
fig = plt.figure()
ax = fig.add_subplot(projection='3d')
# map from unit square to surface of a torus
def torus(u, v):
X = (2 + np.cos(tau*v))*np.cos(tau*u)
@UlisseMini
UlisseMini / plot.py
Created September 5, 2021 01:23
Plot bumpy sphere
import plotly.graph_objects as go
import plotly.express as px
import numpy as np
import pandas as pd
# constants
m, n = 6, 5
pi = np.pi
def vec_x(theta, phi):
import chess
import statistics
import random
def median_move_count(b, depth = 3):
if depth < 0: return []
mvs = []
mvs.append(len(list(b.legal_moves)))
for move in b.legal_moves:
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>owo</title>
<style>
html {
background: #222;
color: #fff;
const Docker = require('dockerode')
const docker = new Docker()
const stripAnsi = require("strip-ansi");
// docker run --cpus=0.1 --memory=64m --kernel-memory=64m --ulimit="nproc=128:128" -i alpine:latest sh -c "$*"
const cmd = process.argv.join(' ')
const kb = 1024
const mb = kb * 1024
"""
Inspired from https://youtu.be/NO_lsfhQK_s (aka blind regex based nosql injection)
"""
import re, time, string
should_sleep = True
binary_search_blind = True
attempts = 0
import time
import struct
DEBUG = True
class Instruction():
def __init__(self, opcode, args, name):
self.opcode = opcode
self.args = args
self.name = name