Skip to content

Instantly share code, notes, and snippets.

View erikseulean's full-sized avatar
🐻

Erik-Cristian S. erikseulean

🐻
  • London
View GitHub Profile
async def scrap_exchanges():
coins = pd.DataFrame.from_csv('crypto/data/coins.csv')
data = defaultdict(lambda:[])
chunks = [coins[i: i + 5] for i in range(0, len(coins), 5)]
for chunk in chunks[0:10]:
with concurrent.futures.ThreadPoolExecutor(max_workers=10) as executor:
futures = [loop.run_in_executor(executor, get_exchanges_for_coin, coin.split(":")[0]) for coin in chunk["Coins"]]
@erikseulean
erikseulean / shortest_substring.py
Created February 5, 2018 17:35
Shortest substring containing all
def shortest_substring(words, text):
total, start, mstart, mend = 0, 0, 0, 0
min_value = len(text)
counts = defaultdict(int)
for i in range(len(text)):
if text[i] in words:
counts[text[i]] = counts[text[i]] + 1
if counts[text[i]] == 1:
total = total + 1
'''
given a final score in a certain sport, get all the possible scores during
the game. the scoring points are given ahead
'''
from copy import copy
def get_scores(points, result):
dp = [0 for _ in range(result + 1)]
dp[0] = 1
'''
compute the minimum number of removals in order to make the string palindrome
'''
def palindromic_substring(word):
dp = [[-1 for _ in range(len(word) + 1)] for _ in range(len(word)+1)]
def count_nr_chars(word, i, j, count):
if dp[i][j] != -1:
def keyboard_path(word):
path = []
current = 'a'
for letter in word:
x,y = get_position(current)
nx, ny = get_position(letter)
path += math.abs(nx - x) * ['down' if nx > x else 'up']
path += math.abs(ny - y) * ['right' if ny > y else 'left']
'''
given a function and a value y, find the bext x for which |f(x) - y| is minimal
'''
def get_boundaries(func, y):
# x * x > max_value #overflow
# sqrt(max_value) < x # next x will be overflow
# in python this is not an issue but it could be in some other languages
@erikseulean
erikseulean / skyline.py
Last active May 30, 2018 21:14
skyline
from heapq import heappop, heappush
class Solution:
def handle_end(self, h, res, item):
end, height = item
while len(h) != 0 and h[0][1] <= end:
heappop(h)
if res[-1][1] == 0 or (len(h) != 0 and abs(h[0][0]) >= height):
return
CURRENT_AGE = 27
BLOOMBERG_MULTIPLICATION_RATE = 2
ESTIMATED_INFLATION_RATE = 0.03
TAX_FREE_AMOUNT = 0.25
ESTIMATED_TAX_VALUE = 0.35
ANUAL_INVESTMENT = 10000
def years_until_retirement():
return 55 - CURRENT_AGE
@erikseulean
erikseulean / sol.py
Created September 18, 2020 16:19
Untangle
sequence="""
SRSRRSSRSRSSRSSRRSSRSSSSSRSSRSSRSRSSRSSRSSSSSSSSRSSRSSSSSRSSRSSRRSSRSSSSSRSSRSSRSSSSSSSSSSSSSSSSSRSSRSSRS
"""
from fractions import Fraction
def decode(seq):
x = 0
for nr in seq:
if nr == 'S':
@erikseulean
erikseulean / post_impact.r
Last active January 25, 2022 16:02
interval
npost = nrow(filter(df, Impact==1))
mm = mean(filter(df, Impact==1)$AbundanceRate)
ll = mm - qnorm(1 - alpha/2) * sd(filter(df, Impact==1)$AbundanceRate)/sqrt(npost)
uu = mm + qnorm(1 - alpha/2) * sd(filter(df, Impact==1)$AbundanceRate)/sqrt(npost)
print(paste("lower", round(ll, 2)))
print(paste("upper", round(uu, 2)))