Skip to content

Instantly share code, notes, and snippets.

@davidrft
davidrft / deadkeys.ahk
Last active May 17, 2020 20:51
AutoHotKey script file to enable dead keys in any keyboard layout.
; Script to enable dead keys in any keyboard layout.
; Source: https://stackoverflow.com/questions/37641744/autohotkey-dead-key-remap-stopped-working
#NoEnv ; Recommended for performance and compatibility with future AutoHotkey releases.
; #Warn ; Enable warnings to assist with detecting common errors.
SendMode Input ; Recommended for new scripts due to its superior speed and reliability.
SetWorkingDir %A_ScriptDir% ; Ensures a consistent starting directory.
#SingleInstance force
#InstallKeybdHook
#NoTrayIcon
@davidrft
davidrft / course_scheduling.py
Created February 9, 2020 20:55
Solution for the leetcode course scheduling problem as seen in riff.ie
from typing import Tuple, Dict, Set, List
AdjacencyList = Dict[int, Set]
EdgeList = List[List[int]]
class Solution:
def buildAdjacencyList(
self, numCourses: int, prerequisites: EdgeList
) -> Tuple[AdjacencyList, Dict[int, int]]:
@davidrft
davidrft / wildcard-trie.py
Created February 6, 2020 11:55
A wildcard trie implementation as seen is riff.ie/posts/wildcard-searching-trie
from typing import Dict, List, Any
WILDCARD = '?'
class Trie:
def __init__(self) -> None:
self.children: Dict[str: Trie] = {}
self.isLeaf: bool = False
def insert(self, key: str) -> None:
import Foundation
protocol Notifier: class {
func notify(_ data: Any)
}
protocol Destroyable {
func destroy()
}
class UnionFind:
def __init__(self):
self.id = {}
self.size = {}
def setdefault(self, p: int):
self.id.setdefault(p, p)
self.size.setdefault(p, 1)
def root(self, i: int) -> int:
from typing import Any, Dict
class Trie:
def __init__(self) -> None:
self.children : Dict[str, Trie] = {}
self.value : Any = None
def find(self, key: str) -> Any:
node = self
for char in key:
class Solution:
def buildGrid(self, stones):
gridSize = max(map(max, stones)) + 1
grid = [[0 for i in range(gridSize)] for i in range(gridSize)]
for x, y in stones:
grid[x][y] = 1
return grid, gridSize
class UnionFind:
def __init__(self):
self.id = {}
self.size = {}
def setdefault(self, p: int):
self.id.setdefault(p, p)
self.size.setdefault(p, 1)
def root(self, i: int) -> int:
@davidrft
davidrft / windows.py
Created October 9, 2019 19:52
Generator of windows from an audio file to short-time analysis
def windows(array, window_size, overlap=0):
""" Generator of windows from an audio file to short-time analysis
Keyword arguments:
array -- Array of audio samples
window_size -- Size of the window that will be generated
overlap -- Overlap of windows to be accounted for when generating new ones
"""
overlap_factor = (1 - overlap)
head, tail = 0, window_size