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 AppKit | |
import ApplicationServices | |
import Cocoa | |
import CoreGraphics.CGGeometry | |
import CoreServices | |
import Foundation | |
func isWindowVisible(_ window: AXUIElement) -> Bool { | |
var value: CFTypeRef? | |
let result = AXUIElementCopyAttributeValue(window, kAXMinimizedAttribute as CFString, &value) |
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
# 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 |
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
# 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()] |
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
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 |
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 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) |
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 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): |
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 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: |
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
<!DOCTYPE html> | |
<html> | |
<head> | |
<meta charset="utf-8"> | |
<title>owo</title> | |
<style> | |
html { | |
background: #222; | |
color: #fff; |
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
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 |
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
""" | |
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 |
NewerOlder