Skip to content

Instantly share code, notes, and snippets.

import time
import sqlite3
DB_NAME = 'comptage.db'
def create_base():
conn = sqlite3.connect(DB_NAME)
c = conn.cursor()
c.execute("""CREATE TABLE IF NOT EXISTS compte (
import Tkinter as tk
from comptage_sql import *
def format_row(t):
return "ID: {}, {}, {}-{}".format(
t[0], "HOMME" if not t[1] else "FEMME",
t[2], t[2] + 10)
def onselect(evt):
@VieVie31
VieVie31 / DFT.py
Created October 17, 2016 20:26
Discrete Fourier Transform
"""
Discrete Fourier Transform
"""
import math
import numpy as np
import matplotlib.pyplot as plt
N = 200 #sample size
x = np.cos(range(N)) #create a periodic cyclic function
r = np.random.random(N) #create some noise
@VieVie31
VieVie31 / background_extraction.py
Created December 3, 2016 16:21
Extract background (in grayscale) from video if the camera is not moving...
import cv2
import numpy as np
from skvideo.io import vreader
VIDEO_PATH = "room.mp4" #my room where i'm moving and i want to remove myself to get only the background...
cap = vreader(VIDEO_PATH)
L = list(cap)
L = map(lambda img: cv2.cvtColor(img, cv2.COLOR_BGR2GRAY), L) #to gray scale
import numpy as np
NB_STATES = input("nb autocollants a collectionner : ")
PROBA = input("probaabilite minimale 'to catch them all' : ") #0.95 par example
#transition matrix
states = np.zeros((NB_STATES, NB_STATES))
#setting tranition probability
for i in range(NB_STATES):
class State:
state_id_counter = 0
def __init__(self, initial=False, final=False):
#setting an unique id
self.id = State.state_id_counter
State.state_id_counter += 1
#setting params
self.initial = initial
self.final = final
from random import *
from psonic import *
#random major scale chord progression from the transitions allowed by:
#http://www.dummies.com/art-center/music/major-and-minor-chord-progressions-for-music-composition/
def get_major_chord(base_note):
"""Take the base note and return a list of 3 notes in
the root position of the major chord of the base note.
import math
import numpy as np
import matplotlib.pyplot as plt
from random import *
def euclidian(v1, v2):
return (sum((v1 - v2) ** 2)) ** .5
@VieVie31
VieVie31 / memory_friendly_class.py
Created March 1, 2019 14:09
just a test with a class with only one attribute... the goal is to serialize the attributes of the class to free memory when too much memory is used... (python 3.7 only)
import gc
import os
import time
import pickle
import psutil
import pathlib
import threading
from dataclasses import dataclass, field
from typing import Any
@VieVie31
VieVie31 / dynamic_properties.py
Last active March 2, 2019 20:32
convert automatically all attribute of a dataclass (inherited from mine) into properties with standard setter/getter to the corresponding hidden attribute and keep in memory the timestamp of the last set/get action on it...
import gc
import os
import re
import time
import types
import pickle
import psutil
import pathlib
import threading