Skip to content

Instantly share code, notes, and snippets.

@danoneata
danoneata / fvecs_read.py
Last active January 19, 2024 20:24
Reading fvecs format in Python
import numpy as np
def fvecs_read(filename, c_contiguous=True):
fv = np.fromfile(filename, dtype=np.float32)
if fv.size == 0:
return np.zeros((0, 0))
dim = fv.view(np.int32)[0]
assert dim > 0
fv = fv.reshape(-1, 1 + dim)
@danoneata
danoneata / fisher_vector.py
Last active December 6, 2023 06:25
Fisher vectors with sklearn
import numpy as np
import pdb
from sklearn.datasets import make_classification
from sklearn.mixture import GaussianMixture as GMM
def fisher_vector(xx, gmm):
"""Computes the Fisher vector on a set of descriptors.
@danoneata
danoneata / visitor.py
Created November 19, 2015 23:41
Visitor pattern in Python
class Expr(object):
def accept(self, visitor):
method_name = 'visit_{}'.format(self.__class__.__name__.lower())
visit = getattr(visitor, method_name)
return visit(self)
class Int(Expr):
def __init__(self, value):
self.value = value
@danoneata
danoneata / color_correction.py
Created September 30, 2022 09:42
Colour correction using a color checker
# This example based on the following tutorial
# https://github.com/colour-science/colour-checker-detection/blob/master/colour_checker_detection/examples/examples_detection.ipynb
import matplotlib.pyplot as plt
import numpy as np
import streamlit as st
import colour
from colour_checker_detection import detect_colour_checkers_segmentation
@danoneata
danoneata / Sudoku.hs
Last active August 20, 2022 01:27
Applicative-based Sudoku solver
{-# LANGUAGE TypeOperators #-}
{-# LANGUAGE GeneralizedNewtypeDeriving #-}
import Control.Applicative
import Data.Char
import Data.List (intersperse)
import Data.Monoid hiding (All, Any)
import Data.Foldable hiding (all, any)
import Prelude hiding (all, any)
@danoneata
danoneata / example.py
Created June 7, 2022 14:07
JSON decoder in Python
from main import *
@dataclass
class Measurment:
temp: float
humidity: float
# date: datetime
@danoneata
danoneata / main.py
Created April 21, 2018 12:33
Time series classification for gesture recognition
import argparse
import pdb
import os
import sys
from collections import namedtuple
import numpy as np
import pandas as pd
@danoneata
danoneata / .tmux.conf
Created December 15, 2020 10:39
dotfiles
# Remap prefix to C-q.
set -g prefix C-q
unbind C-b
bind C-q send-prefix
# Use C-q C-q to go back to the last window.
bind-key C-q last-window
# Faster command sequences.
set -s escape-time 0
@danoneata
danoneata / gauss2d.py
Last active May 5, 2020 12:58
Plot a 2D Gaussian
import numpy as np
import pdb
from matplotlib import pyplot as plt
from scipy.stats import multivariate_normal
def gauss2d(mu, sigma, to_plot=False):
w, h = 100, 100
std = [np.sqrt(sigma[0, 0]), np.sqrt(sigma[1, 1])]
@danoneata
danoneata / README.md
Created June 21, 2019 12:23
Unix shell intro

Intro

  • shell takes commands and passes to the operating system
  • most popular shell is bash (Bourne Again Shell): a replacement of sh, the origianl Unix shell, which was written by Steve Bourne
  • motivating examples:
# Copies all HTML files to `destination`,
# but only those that do not exist or are newer
cp -u *.html destination