Skip to content

Instantly share code, notes, and snippets.

View lpraat's full-sized avatar
😃

Lorenzo Pratissoli lpraat

😃
View GitHub Profile
@lpraat
lpraat / conj.py
Created March 15, 2020 15:44
Conjugate gradient algorithm
import tensorflow as tf
from src.utils.dtypes import tf_float_type
def conj_gradient(A, b, iters):
# todo can be optimized
x = tf.zeros_like(b)
r = b - tf.matmul(A, x)
p = r
import matplotlib.pyplot as plt
from matplotlib import animation
import numpy as np
fig = plt.figure()
ax = plt.axes(xlim=(-2,5), ylim=(0,10))
line, = ax.plot([], [])
"""
Example showing that backward pass of conv layer can be done using transposed convolution
"""
import numpy as np
a_prev = np.array([
[1,1,1,1],
[2,2,2,2],
[3,3,3,3],
[4,4,4,4]
@lpraat
lpraat / audio.py
Last active May 10, 2023 17:37
Audio(from mic) signal + spectrum visualizer in python
import pyaudio
import numpy as np
import matplotlib.pyplot as plt
from scipy.fftpack import fft
import matplotlib.animation as animation
CHUNK = 1024 # signal is split into CHUNK number of frames
FORMAT = pyaudio.paInt16
1. Create virtualenv
2. source created_env/bin/activate
3. (created_env) pip install ipykernel
4. (created_env) ipython kernel install --user --name=created_env
5. jupyter kernelspec list
6. go in the folder of your newly created kernel and verify it correctly points to the python executable of the newly created
environment(this can be seen in kernel.json file)
@lpraat
lpraat / fs.py
Created June 23, 2018 10:29
Format Strings generator for x86
def little_endian(hex_str):
hex_str = fix_hex(hex_str)
chars = [hex_str[i:i+2] for i in range(0, len(hex_str), 2)][::-1]
return bytes.fromhex("".join(chars))
def remove0x(hex_str):
return hex_str[2:]
def half(hex_str):
hex_str = fix_hex(hex_str)
@lpraat
lpraat / langton.py
Last active September 27, 2017 18:37
Langton's Ant
import turtle
import sys
def update_maps(graph, turtle, color):
graph[turtle_pos(turtle)] = color
def turtle_pos(turtle):
return (round(turtle.xcor()), round(turtle.ycor()))
@lpraat
lpraat / sudoku.c
Created October 2, 2015 14:08
Sudoku solver
#include <stdio.h>
#define ORDER 3
#define DIM ORDER*ORDER
int checkLine(int m[DIM][DIM], int line)
{
int i, j;
for (i = 0; i < DIM-1; i++)
for (j = i+1; j < DIM; j++)
if (m[line][i] == m[line][j] &&