Skip to content

Instantly share code, notes, and snippets.

View akiross's full-sized avatar
🥷
Ninja

Alessandro Re akiross

🥷
Ninja
View GitHub Profile
@akiross
akiross / img_selector.py
Last active May 18, 2018 10:24
Could be useful to let a human pick an image in a small set.
import cv2
import tkinter
from PIL import Image, ImageTk
def inter_evo(solutions, geometry=None, load=False, to_pil=False):
"""Ask user to select one image among the set.
Will open a window with some buttons and images over those buttons,
returns the index of the clicked image (button).
@akiross
akiross / asyncinit.py
Last active March 1, 2018 18:41
How to use async __init__ magic method in Python
import asyncio
class AsyncClass:
async def __new__(cls, *args, **kwargs):
o = super().__new__(cls)
# Explicit async call
await o.__init__(*args, **kwargs)
return o # __init__ will be called anyway
async def __init__(self, *args, **kwargs):
@akiross
akiross / pandas_data_index.py
Created July 18, 2017 07:54
Simple example on using dates as index
#!/usr/bin/env python3
import pandas as pd
import io
# Make up some data
example_csv = '''Birthday,Name,Surname
1643-01-04,Isaac,Newton
1879-03-14,Albert,Einsten
1942-01-08,Stephen,Hawking
@akiross
akiross / prime_numbers.py
Created July 6, 2017 12:06
Generating prime numbers in chunks
def extend(old, new):
for p in old:
cand = []
for n in new:
if n % p != 0:
cand.append(n)
if not cand:
return old
old.append(cand[0])
new = cand[1:]
@akiross
akiross / pigreco.cu
Last active February 17, 2025 23:07
Approximate Pi using usual Monte-Carlo simulation, in CUDA (with bonus Python snippet!).
// Approximation of Pi using a simple, and not optimized, CUDA program
// Copyleft Alessandro Re
//
// GCC 6.x not supported by CUDA 8, I used compat version
//
// nvcc -std=c++11 -ccbin=gcc5 pigreco.cu -c
// g++5 pigreco.o -lcudart -L/usr/local/cuda/lib64 -o pigreco
//
// This code is basically equivalent to the following Python code:
//
@akiross
akiross / Understanding_queues_in_TF.ipynb
Created April 3, 2017 16:50
This notebook aims to explain how queues are used in tensorflow, in a bit more practical way than the official docs. I developed and tested this with TF 1.0
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@akiross
akiross / autoencoder.ipynb
Created March 22, 2017 12:04
Super-simple autoencoder with tensorflow and MNIST data
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@akiross
akiross / google_hash_code_deap.py
Created February 23, 2017 21:40
Google Hash Code 2017 - Youtube video caching solution using Genetic Algorithms
#!/usr/bin/env python3
'''So, I entered the Google Hash Code 2017 competition with a team named PiedPiper,
with a guy from UK and a girl from Palestine, but in the end each one of us worked
in her/his own. I came up with a solution using Genetic Algorithms (via DEAP).
I used the score function to build an algorithm that used 1-bit encodings to represent
the presence of a video over a certain cache server.
I wasted some time during the competition, so I managed to run briefly the algo on the
@akiross
akiross / zshrc
Created January 13, 2017 16:35
A very handy function to auto-activate specific python virtual environments upon entering a directory containing a magic file.
# Setup python virtual environment in a given directory subtree
function chpwd_auto_pyvenv() {
local MAGIC=".zsh_pyvenv"
# Check if we encountered a magic previously
if [[ -z ${ZSH_PYVENV_PARENT+x} ]]; then
# Check if this directory contains a MAGIC
if [[ -a "$PWD/$MAGIC" ]]; then
echo "Activating virtual environment"
# Activate the environment specified
@akiross
akiross / Convolutional Arithmetic.ipynb
Last active October 24, 2024 07:04
Few experiments on how convolution and transposed convolution (deconvolution) should work in tensorflow.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.