Skip to content

Instantly share code, notes, and snippets.

View matiasmicheletto's full-sized avatar
🏠
Working from home

Matias Micheletto matiasmicheletto

🏠
Working from home
View GitHub Profile
@matiasmicheletto
matiasmicheletto / bus_race.py
Last active July 17, 2024 14:04
Bus race for console :)
import time
import random
import os
import math
buses_names = ["CONDOR", "PLUSMAR", "RAPIDO", "FLECHA"]
def clear_console():
os.system('cls' if os.name == 'nt' else 'clear')
@matiasmicheletto
matiasmicheletto / tictactoe.html
Created January 5, 2023 20:45
Minimalist tic tac toe game in JS
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Tic Tac Toe</title>
<meta name="description" content="Tic Tac Toe game">
<meta name="author" content="Matias Micheletto">
</head>
@matiasmicheletto
matiasmicheletto / imgResize.js
Created December 1, 2022 16:44
Resize a base64 image with javascript
const imgResize = (base64, factor) => {
return new Promise((resolve, reject) => {
const watchdog = setTimeout(()=>{
reject(new Error("TIMEOUT"));
}, 5000); // If image loading takes too long
const canvas = document.createElement("canvas");
const img = new Image();
img.onload = function () {
clearTimeout(watchdog);
canvas.width = Math.round(img.width*factor);
@matiasmicheletto
matiasmicheletto / codelinecounter.sh
Created November 6, 2022 00:27
Count the lines of code in a software project using linux bash command
# Recursively count the total number of lines of code in .js and .jsx files found in a directory.
find . -name '*.js' -o -name '*.jsx' | xargs wc -l
@matiasmicheletto
matiasmicheletto / base64SHA256Hash.js
Created October 26, 2022 20:20
Compute base64 SHA-256 hash in browser
const hash = message => {
return new Promise((resolve, reject) => {
const msgBuffer = new TextEncoder().encode(message);
crypto.subtle.digest('SHA-256', msgBuffer)
.then(hashBuffer => {
const hashArray = Array.from(new Uint8Array(hashBuffer));
const hexString = hashArray.map(b => b.toString(16).padStart(2, '0')).join('');
const str = hexString
.replace(/\r|\n/g, "")
.replace(/([\da-fA-F]{2}) ?/g, "0x$1 ")
@matiasmicheletto
matiasmicheletto / haversine.js
Created October 8, 2022 00:56
Compute distance in km between two coordinates using the haversine formula
const haversine = (pos1, pos2) => {
// https://stackoverflow.com/questions/639695/how-to-convert-latitude-or-longitude-to-meters
const R = 6378.137; // Radius of Earth
const dLat = pos2.lat * Math.PI / 180 - pos1.lat * Math.PI / 180;
const dLon = pos2.lng * Math.PI / 180 - pos1.lng * Math.PI / 180;
const a = Math.sin(dLat/2) * Math.sin(dLat/2) +
Math.cos(pos1.lat * Math.PI / 180) * Math.cos(pos2.lat * Math.PI / 180) *
Math.sin(dLon/2) * Math.sin(dLon/2);
return (R * 2 * Math.atan2(Math.sqrt(a), Math.sqrt(1-a)));
};
@matiasmicheletto
matiasmicheletto / index.html
Created June 25, 2022 15:06
JS para computación científica: Estimación de PI con método Monte Carlo
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<!-- Título de la página, visible en la barra del navegador -->
<title>Método Monte Carlo en el navegador</title>
</head>
<body>
<div style="margin:15px;">
@matiasmicheletto
matiasmicheletto / roflcopter.js
Created March 31, 2022 20:44
Roflcopter for NodeJS!
const frame = [
["\n\n\n\n","ROFL:ROFL:LOL\n"," ___^_____\n"," L __/ [] \\\n"," O === \\\n"," L \\____________]\n"," I I\n"," ------------/\n"],
["\n\n\n\n"," :LOL:ROFL:ROFL\n"," ___^_____\n"," __/ [] \\\n","LOL=== \\\n"," \\____________]\n"," I I\n"," ------------/\n"]
];
let index=0;
setInterval(()=>{
console.clear();
console.log(frame[(index++)%2].join(' '.repeat(index)));
}, 100);
@matiasmicheletto
matiasmicheletto / tf-image-stilizer.py
Created August 30, 2021 12:40
Test for the image style transfer by Ghiasi et al.
# Check it working on: https://www.kaggle.com/matiasmiche/image-stylization
import matplotlib.pyplot as plt
import tensorflow_hub as hub
import tensorflow as tf
import numpy as np
import cv2
content_filename = 'content_image.jpg'
style_filename = 'style_image.jpg'
@matiasmicheletto
matiasmicheletto / lcd_xmas.ino
Created December 17, 2020 18:23
LCD 2004 I2C xmas message
#include <Wire.h>
#include "LiquidCrystal_I2C.h"
/* If address is not 0x27, then try 0x3F */
LiquidCrystal_I2C lcd(0x27,20,4);
/* Custom characters */
byte c0[8] = {0x00,0x00,0x00,0x00,0x01,0x03,0x07,0x0F};
byte c1[8] = {0x04,0x0E,0x1F,0x1F,0x1F,0x1F,0x1F,0x1F};
byte c2[8] = {0x00,0x00,0x00,0x00,0x10,0x18,0x1C,0x1E};