Skip to content

Instantly share code, notes, and snippets.

@davidrft
davidrft / deadkeys.ahk
Last active May 17, 2020
AutoHotKey script file to enable dead keys in any keyboard layout.
View deadkeys.ahk
; 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 Feb 9, 2020
Solution for the leetcode course scheduling problem as seen in riff.ie
View course_scheduling.py
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 Feb 6, 2020
A wildcard trie implementation as seen is riff.ie/posts/wildcard-searching-trie
View wildcard-trie.py
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:
View observer-demo.swift
import Foundation
protocol Notifier: class {
func notify(_ data: Any)
}
protocol Destroyable {
func destroy()
}
View uf.py
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:
View trie.py
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:
View 947-dfs.py
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
View 947-uf.py
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 Oct 9, 2019
Generator of windows from an audio file to short-time analysis
View windows.py
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