Skip to content

Instantly share code, notes, and snippets.

View grevych's full-sized avatar
🤓

Gerardo Reyes grevych

🤓
View GitHub Profile
@grevych
grevych / flatten_dict.py
Created January 4, 2024 15:19
Flatten python dictionary
def flatten_dict(d: any):
if not isinstance(d, dict):
return []
flat_d = _flatten_dict(d)
for index in range(len(flat_d)):
flat_d[index] = tuple(flat_d[index])
return flat_d
@grevych
grevych / hacky_vcr_helpers.rb
Created November 24, 2021 19:09
Hacky VCR Cassettes
require 'vcr'
module HackyVCRHelpers
def extract_headers_from(request)
{
'content_length' => request.headers.env['CONTENT_LENGTH'],
'content_type' => request.headers.env['CONTENT_TYPE'],
'http_accept' =>request.headers.env['HTTP_ACCEPT'],
'http_host' => request.headers.env['HTTP_HOST'],
'path_info' => request.headers.env['PATH_INFO'],
@grevych
grevych / upload-cassettes.sh
Created November 16, 2021 20:50
Upload vcr cassettes to s3 based on hash strategy
#!/usr/bin/env bash
set -ex
summary () {
# MacOS - local testing
# echo "$(stat -f '%z' "$1") $(md5sum "$1")"
# Linux
echo "$(stat -c '%s' "$1") $(md5sum "$1")"
@grevych
grevych / funo.rkt
Last active September 24, 2021 09:47
Write a function in racket that receives a list of lists of numbers and return the product of all the elements in the lists
(define (FUNO L)
(cond
[(list? L)
(cond
[(empty? L) 1]
[(equal? (length L) 1) (FUNO(first L))]
[(* (FUNO(first L)) (FUNO (rest L)))]
)
]
[else L]
@grevych
grevych / polish_notation.py
Created July 28, 2021 18:23
Polish notation using two stacks
def solve(polish_notation):
polish_notation = polish_notation.split()
operands = []
operators = []
operations = {
'+': lambda x, y: x + y,
'-': lambda x, y: x - y,
'*': lambda x, y: x * y,
'/': lambda x, y: x / y
}
@grevych
grevych / binary_substring.py
Created September 17, 2020 01:30
Find if a binary representation of an integer is a repeated (maybe incomplete) substring
def solution(n):
d = [0] * 30
l = 0
while (n > 0):
d[l] = n % 2
n //= 2
l += 1
for p in range(1, l - 1):
ok = True
print(d[:l-p])
@grevych
grevych / substring_groups.py
Created September 17, 2020 01:24
Find the number of possible combinations for groups of 3 substrings with the same amount of letter `a`
from collections import Counter
def solution_aux(S, groupSize, groups, numberOfAs):
print(groups, S, numberOfAs)
if len(groups) == 3:
if len(S) == 0:
print('count')
return 1
@grevych
grevych / design.md
Created August 21, 2020 11:31 — forked from nateklaiber/design.md
API Client Design
@grevych
grevych / shuffle.js
Created August 7, 2020 13:24
Shuffle an array of objects by a given selector key
class LimitedSet {
constructor(size) {
this.size = size
this.queue = []
this.set = new Set()
}
has(key) {
return this.set.has(key)
}
@grevych
grevych / board.py
Last active October 31, 2019 00:54
ASCII Printer
class Board(object):
def __init__(self, wide, tall):
self.__wide__ = wide
self.__tall__ = tall
self.__area__ = [[None for _ in range(wide)] for _ in range(tall)]
self.__validate_wide__(wide)
self.__validate_tall__(tall)
def __validate_wide__(self, wide):