This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Using a a arduino keypad module from scratch, without using extra libraries. | |
// In this case, one columns is targeted. | |
// This gist is a complement to https://youtu.be/1iPnFEWHnqo, where this is explained | |
int pinSource = 3; | |
int pinReceiver1 = 9; | |
int pinReceiver2 = 8; | |
int pinReceiver3 = 7; | |
int pinReceiver4 = 6; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Using a a arduino keypad module from scratch, without using extra libraries. | |
// In this case, two columns are targeted | |
// This gist is a complement to https://youtu.be/1iPnFEWHnqo, where this is explained | |
int pinSource1 = 3; | |
int pinSource2 = 4; | |
int pinReceiver1 = 9; | |
int pinReceiver2 = 8; | |
int pinReceiver3 = 7; | |
int pinReceiver4 = 6; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/zsh | |
# See this blog article on how to create Obsidian automatic encrypted backups, on Obsidian application quit, or any other event: | |
# https://lopespm.com/notes/2024/09/11/obsidian-backup.html | |
# | |
obsidian_notes_folder="<your_obsidian_folder>" ; # For example, /Users/yourusername/Library/Application Support/obsidian | |
obsidian_notes_tar_archive="${obsidian_notes_folder}/obsidian_backup.tar.gz" ; | |
backup_folder="<folder_where_the_final_encrypted_backup_will_be_placed>"; # For example, /Users/yourusername/Library/CloudStorage/GoogleDrive/MyDrive/backup_folder | |
echo "Starting to compress obsidian notes..." ; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# In this example, we get the maximum content length for the intfloat/multilingual-e5-large model (https://huggingface.co/intfloat/multilingual-e5-large) | |
from transformers import AutoConfig | |
checkpoint = "intfloat/multilingual-e5-large" | |
config = AutoConfig.from_pretrained(checkpoint) | |
print(f"Maximum context length for this model: {config.max_position_embeddings}") | |
### Output "Maximum context length for this model: 514" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# https://stackoverflow.com/a/34435207/1765893 | |
git rm -r --cached . | |
git add . | |
git commit -m "Remove all ignored files in .gitignore" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# This solution to compute a random subset avoids the use of extra auxiliary space, with O(k + n) time complexity and O(1) space complexity, in Python (5.15 Compute a random subset, on EPI (Elements of Programming Interviews)) (September 2018 edition)). | |
# The idea here is to pick the r-th combination, and find its constituents by incrementing them in a Odometer like fashion, and taking into account that the next digit in the combination will be greater than the previous one. | |
# For example, the combination sequence for n=5 and k=2 is: | |
# 0 - [0,1] | |
# 1 - [0,2] | |
# 2 - [0,3] | |
# 3 - [0,4] | |
# 4 - [1,2] | |
# 5 - [1,3] | |
# 6 - [1,4] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Alternative python solution for 9.12 Reconstruct a binary tree from a preorder traversal with markers on EPI (Elements of Programming Interviews)) (September 2018 edition) | |
# Time complexity: O(n) | |
# Space complexity: O(n + h) - the size of the hash table plus the maximum depth of the function call stack | |
class BstNode: | |
def __init__(self, data, left=None, right=None): | |
self.data = data | |
self.left = left | |
self.right = right | |
def __repr__(self): |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Alternative python solution for 5.17 The Sudoku Check Problem on EPI (Elements of Programming Interviews)) (September 2018 edition) | |
# For an nxn Sudoku grid: | |
# Time complexity: O(n^2) | |
# Space complexity: O(n) | |
from typing import List | |
import math | |
from typing import List, Set | |
import math |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# (Variant #4 for exercise 16.2 on EPI (Elements of Programming Interviews)) (September 2018 edition) | |
# The core idea is calculate the levenshtein distance, while taking into account the special cases of the regex expression | |
# *, +, ? and . were taken into account for the regex expression. Expression blocks are not supported | |
# This algorithm uses dynamic programming, yielding a O(mn) time complexity, O(m) auxiliary space for cache | |
# (m and n are the lengths of regex and target strings respectively) | |
# | |
# Version using recursion with memoization: https://gist.github.com/lopespm/53a215d0b2b0518b52b6bb6687bdaff6 | |
def regex_dist(regex: str, target: str): |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# (Variant #4 for exercise 16.2 on EPI (Elements of Programming Interviews)) (September 2018 edition) | |
# The core idea is calculate the levenshtein distance, while taking into account the special cases of the regex expression | |
# *, +, ? and . were taken into account for the regex expression. Expression blocks are not supported | |
# This algorithm uses recursion with memoization (could be transposed to a DP solution), yielding a O(mn) time complexity, O(mn) auxiliary space for cache and O(max(m,n)) function call stack | |
# (m and n are the lengths of regex and target strings respectively) | |
# | |
# Version using dynamic programming: https://gist.github.com/lopespm/2362a77e7bd230a4622a43709c195826 | |
def regex_dist(regex: str, target: str): | |
def regex_dist_aux(r_i, t_i): |
NewerOlder