Skip to content

Instantly share code, notes, and snippets.

View josepdecid's full-sized avatar

Josep de Cid josepdecid

View GitHub Profile
@josepdecid
josepdecid / rpn.rb
Last active February 6, 2017 21:37
RPN Calculator kata solution (Ruby)
class RPN
def initialize(operation)
@operation = operation.split(' ')
end
def calculate
stack = []
@operation.each do |value|
if is_operator?(value)
@josepdecid
josepdecid / PDDL.tex
Created September 19, 2017 13:37
PDDL Latex syntax highlighting
\definecolor{mygreen}{rgb}{0,0.6,0}
\definecolor{myorange}{rgb}{1.0,0.5,0.3}
\definecolor{mymauve}{rgb}{0.58,0,0.82}
\definecolor{myblue}{rgb}{0.05,0.19,0.57}
\definecolor{mygrey}{rgb}{0.4,0.4,0.4}
\definecolor{myred}{rgb}{0.9,0.2,0.15}
\lstdefinelanguage{pddl}
{
sensitive=false, % not case-sensitive
@josepdecid
josepdecid / ColabReconnect.js
Last active November 2, 2023 10:06
Colab Reconnect
// Interval time to check if runtime is disconnected
interval = 1000 * 60;
// Busy/Reconnect button top-right
reloadButton = document.querySelector('#connect > paper-button > span')
setInterval(() => {
if (reloadButton.innerText == 'Reconnect') {
reloadButton.click();
console.log('Restarting');
@josepdecid
josepdecid / ngram_distance.py
Created June 8, 2020 18:10
N-gram distance between two strings
def get_n_grams(s, n):
n_grams = []
i = 0
while i + n <= len(s):
n_grams.append(s[i:i + n])
i += 1
return set(n_grams)
def n_gram_distance(s1, s2, n, case_sensitive=False):
@josepdecid
josepdecid / ngram_count_mle_lap.py
Last active June 9, 2020 19:17
N-gram occurences counter with MLE and LAP
from typing import List, Set, Optional
from fractions import Fraction
from collections import Counter
import termtables as tt
def count_n_grams(l: List[str], n: int, alpha: float, vocab: Optional[Set[str]] = None):
n_grams = []
i = 0
@josepdecid
josepdecid / BakeMultipleNavMesh.cs
Created December 8, 2020 21:01
Unity: Bake a NavMesh dynamically from multiple surfaces
GameObject[] walkableSurfaces = GameObject.FindGameObjectsWithTag("Floor");
CombineInstance[] objectsToCombine = new CombineInstance[walkableSurfaces.Length];
for (int i = 0; i < walkableSurfaces.Length; ++i)
{
MeshFilter meshFilter = walkableSurfaces[i].GetComponent<MeshFilter>();
// Extract mesh from each walkable surface (floor)
objectsToCombine[i].mesh = meshFilter.sharedMesh;
objectsToCombine[i].transform = meshFilter.transform.localToWorldMatrix;
@josepdecid
josepdecid / auto-dragons-lair.py
Created November 25, 2023 22:17
Small script that auto-plans Dragon's Lair using the minimum number of dependencies possible, Win32 and Numpy. I've only been able to test it with the Steam version and it works playing with the "Arcade Cabinet" and "Move Guide" options set to ON. Some of the stuff is slightly hardcoded and values are extracted from a standard 1920x1080 screen.
import time
import numpy as np
import win32api
import win32gui
import win32ui
import win32con
from PIL import Image
def get_window_screenshot():