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 torch | |
import torch.nn.functional as F | |
from PIL import Image | |
# Check CUDA availability | |
device = "cuda" if torch.cuda.is_available() else "cpu" | |
game_of_life_kernel = torch.tensor([ | |
[1, 1, 1], | |
[1, 0, 1], |
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
""" | |
There are a surprising number of integers where the square root can be written | |
as the sum of the digits of the original minus 2. Even more if you're willing | |
to group digits together in order to make the sum work. This program finds all | |
299 such examples for n < 10e9. Ultimately this works because the square root | |
of a number tends to have roughly half as many digits as the original number, | |
so if you break a number in half, you'll already be in the ballpark of the | |
square root. For example, `sqrt(442,225) = 665 = (442 + 225) - 2`. The minus | |
two is arbitary - this works for other offsets as well - but offset 2 gets | |
you six matches for n <= 289 so it looks impressive right out of the gate. |
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
<script src="quine_clock_explained.js"></script> | |
<style> | |
body { | |
background-color: black; | |
color: #FFF; | |
padding: 9vw; | |
font-size: 20px; | |
} | |
</style> |
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 sys | |
import csv | |
import random | |
from PIL import Image, ImageDraw | |
import matplotlib.pyplot as plt | |
import numpy as np | |
# Constants | |
COLORS = ['red', 'blue', 'green', 'orange', 'purple'] | |
SHAPES = ['circle', 'square', 'triangle', 'plus', 'diamond'] |
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
TARGET_HOST=prometheus | |
# for each user with a home directory | |
for USER in `ls /home`; do | |
# if the user has a known_hosts files | |
echo "checking /home/$USER/.ssh/known_hosts..." | |
if [ -f /home/$USER/.ssh/known_hosts ]; then | |
# remove the outdated key |
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
server { | |
server_name api.oranlooney.com; | |
listen 80; | |
# additional security | |
server_tokens off; | |
add_header X-Frame-Options "DENY"; | |
add_header X-Content-Type-Options nosniff; | |
# performance |
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
from scipy.optimize import linear_sum_assignment | |
import numpy as np | |
def maximize_trace(X): | |
""" | |
Maximize the trace of a square matrix using only row and | |
column permutations. Furthermore, sort the trace | |
in desending order so that largest value ends | |
up the upper left and the smallest in the lower right. | |
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 os | |
import sys | |
from time import sleep | |
from threading import Thread | |
from queue import Queue | |
import codecs | |
def hard_work(x): | |
for n in range(100001): | |
x = codecs.encode(x, 'rot_13') |
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
from typing import NamedTuple, Any, Optional | |
class Node(NamedTuple): | |
"""A single Node in a binary tree.""" | |
value: Any | |
left: Node | |
right: Node | |
def count(node: Optional[Node]) -> int: | |
"""Count the total number of nodes in a tree rooted at this node.""" |
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
X = np.hstack([np.ones(shape=(23, 1)), np.random.normal(size=(23, 2))]) | |
Theta = np.array([0.5, +0.1, -0.2]).reshape( (3, 1) ) | |
Y = X @ Theta + np.random.normal(0, 0.1, size=(23, 1)) | |
Theta_hat = np.linalg.inv(X.T @ X) @ X.T @ Y | |
Theta_hat |
NewerOlder