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
""" | |
Monte Carlo integration of functions on subsets of the real line, | |
using uniform probability distributions | |
""" | |
import math | |
import random | |
def montecarlo(f, g, a, b): | |
""" |
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
// A mock reference monitor design for a mock security system, enforcing the following access control policy: | |
// Only the user 'Alice' who identifies herself on requested inputs | |
// with her name and her birthday of '01.01.1980' is granted access to | |
// the top secret recipe file, stored on disk. | |
// This reference monitor design provides (some) security towards the given access policy | |
// by a) storing a hash rather than the values of the user inputs of (name, birthday) to compare against, | |
// and b) using a salt of the valid inputs as a symmetric key for AES encrypting the top secret recipe file beforehand and | |
// for decrypting before returning to Alice. | |
// | |
// Of course these comments would not be kept in the source code. |
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
# insecure_deserialization.py | |
""" | |
as stated in the docs (https://docs.python.org/3/library/pickle.html): | |
'Warning The pickle module is not secure. Only unpickle data you trust.' | |
""" | |
import os |
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 | |
def hom1(f, x0, dx0, delta, n): | |
sol = [x0] | |
x1, dx = x0 + dx0 * delta, dx0 | |
for _ in range(n-1): | |
x0, x1, dx = x1, f(x0) * delta + x0, 1.0 * (x1 - x0) / delta | |
sol.append(x0) | |
return sol |
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
""" | |
a basic redundant bits encoder-decoder | |
""" | |
import json | |
import random | |
import sys | |
SAMPLE_PAYLOAD = {"foo": 1, "bar": 2} | |
FLIP_PROB = 0.05 |
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
""" | |
Program demonstration that a single-layer linear autoencoder | |
is equivalent to principal component projection | |
""" | |
import numpy as np | |
import tensorflow as tf | |
class A1(object): |
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
#include <iostream> | |
#define SIZE 3 | |
#define EMPTY 'e' | |
#define BIGNUM 100 | |
#define MAXNUMSTATES 10000 | |
enum Player {Player1 = 'x', Player2 = 'o'}; | |
struct state { |
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 random | |
EMPTY = ' ' | |
PLAYER1 = 'x' | |
PLAYER2 = 'o' | |
DIM = 3 | |
def player_wins(state, player): | |
anycol = any(all(state[i][j] == player for i in range(DIM)) for j in range(DIM)) | |
anyrow = any(all(state[j][i] == player for i in range(DIM)) for j in range(DIM)) |
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
/*--------------------------------- | |
minimax example | |
/ | \ | |
/ \ / \ / | \ | |
/\ /\ /\ /\ /\ /\ /\ | |
2 7 8 1 4 5 9 0 3 6 5 1 2 1 | |
becomes | |
7 |
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
# stack_computations.py | |
""" | |
Simple example stack computations | |
""" | |
""" | |
Stack diagram | |
f(n) | |
f(n-1) |