Skip to content

Instantly share code, notes, and snippets.

View ekaitz-zarraga's full-sized avatar
🏠
Working from home

Ekaitz Zárraga ekaitz-zarraga

🏠
Working from home
View GitHub Profile
@ekaitz-zarraga
ekaitz-zarraga / db.py
Last active March 31, 2024 19:38 — forked from ZiTAL/db.py
Dragoi Bola: Twitch plataforman 24/7 martxan!
import os
import sys
import re
import tempfile
from ffmpeg import FFmpeg, Progress # use `python-ffmpeg`
from datetime import datetime, timedelta
from collections import OrderedDict
sys.path.append('../../')
from src.TwitchFfmpeg import TwitchFfmpeg, TwitchConfig
@ekaitz-zarraga
ekaitz-zarraga / image_recursively.py
Last active July 13, 2023 10:53
Another shitty example :)
from PIL import Image
from os import path as p
import os
import argparse
def process_image(im):
size = im.size
menor = min(size)
return im.crop((0,0,menor,menor)) \
.resize((256,256)) \
@ekaitz-zarraga
ekaitz-zarraga / lagrange_interp.py
Created July 7, 2023 08:48
Lagrange Interpolation using a closure and a namedtuple vs a class and a dataclass
from collections import namedtuple
Point = namedtuple('Point', ['x', 'y'])
def lagrange_interp(points):
def interp(x):
y = 0
for pj in points:
l = 1
xj = pj.x
@ekaitz-zarraga
ekaitz-zarraga / tictactoe.py
Last active June 28, 2023 12:23
A shitty tictactoe minimax implementation that doesn't actually work yet
def create_board():
board = {}
for i in ["a","b","c"]:
for j in ["1","2","3"]:
board[i+j] = " "
return board
def ganador(board):
if board["a1"] == board["b1"] == board["c1"] and board["a1"] != " ":
@ekaitz-zarraga
ekaitz-zarraga / MYSQL_SESSION_EXAMPLE.txt
Created March 17, 2023 08:32
Example session in MySQL from scratch: Creates a user for password auth and a database.
alumno ~$ sudo apt install mysql-server mysql-client
[sudo] contraseña para alumno:
Leyendo lista de paquetes... Hecho
Creando árbol de dependencias
Leyendo la información de estado... Hecho
mysql-client ya está en su versión más reciente (8.0.32-0ubuntu0.20.04.2).
mysql-server ya está en su versión más reciente (8.0.32-0ubuntu0.20.04.2).
0 actualizados, 0 nuevos se instalarán, 0 para eliminar y 16 no actualizados.
alumno ~$ sudo mysql
Welcome to the MySQL monitor. Commands end with ; or \g.
@ekaitz-zarraga
ekaitz-zarraga / SQLiteSessionExample.txt
Created March 14, 2023 12:25
Example SQLite session with keys and a lot of fun
$ sqlite3 DATOS.db
SQLite version 3.31.1 2020-01-27 19:55:54
Enter ".help" for usage hints.
sqlite> .read tareas.sql
sqlite> .dump
PRAGMA foreign_keys=OFF;
BEGIN TRANSACTION;
CREATE TABLE personas(
id INTEGER PRIMARY KEY,
name TEXT
@ekaitz-zarraga
ekaitz-zarraga / markov_greeter.js
Last active March 6, 2023 17:06
Markov text generator example ftw. Run with `node markov_greeter.js` several times to watch it do its magic.
// TRANSITION DAG
//////////////////////////////////////////////////////////////////////////////
let areYou = {
value: " are you!",
transitions: []
};
let questionMark = {
value: "?",
@ekaitz-zarraga
ekaitz-zarraga / mymap.js
Created March 3, 2023 13:24
a JavaScript Map that compares keys by equality and not by reference LUL
function MyMap(){
this.map = new Map();
}
MyMap.prototype.set= function(k,v){
this.map.set(JSON.stringify(k), v);
}
MyMap.prototype.get= function(k){
return this.map.get(JSON.stringify(k));
}
@ekaitz-zarraga
ekaitz-zarraga / gol_example.js
Created March 1, 2023 13:17
A minimal and dirty example of Conway's Game of Life in javascript
let grid = [
[0, 0, 0],
[1, 1, 1],
[0, 0, 0]
];
function vecinasPosibles(x,y,grid){
return [
[x-1,y-1],[x+0,y-1],[x+1,y-1],
[x-1,y+0], [x+1,y+0],
@ekaitz-zarraga
ekaitz-zarraga / bisection.clj
Last active January 24, 2019 09:18
Example code for Bisection method in Clojure
; Example code for Bisection method
; https://en.wikipedia.org/wiki/Bisection_method
(defn f
"Example function to apply algorithm on"
[x]
(+ 3 x))
(defn distance
[a b]