Skip to content

Instantly share code, notes, and snippets.

View erikseulean's full-sized avatar
🐻

Erik-Cristian S. erikseulean

🐻
  • London
View GitHub Profile
def find_perfect_squares(number):
perfect_squares = {i * i for i in range(sqrt(n)}
for other_i in sqrt(n):
if n - other_i * other_i in perfect_squares:
return True
return False
from collections import defaultdict
class ConversionNotPossible(Exception):
def __init__(self, from_unit, to_unit):
super(Exception).__init__()
self.from_unit = from_unit
self.to_unit = to_unit
def __repr__(self) -> str:
from functools import lru_cache
def minCut(s: str) -> int:
def is_palindrome(start, end):
while start < end:
if s[start] != s[end]:
return False
start += 1
@erikseulean
erikseulean / five_stop.py
Last active April 13, 2022 22:04
Stop thread after 5 seconds
import threading
import time
def do_something_random_until_stopped(event):
counter = 0
elapsed = time.time()
while not event.isSet():
print(f"I am at {counter}")
counter += 1
<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="width=device-width" />
<title>ngErrorRedirect</title>
</head>
<body>
<div>
Error
</div>
@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)))
@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':
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 / 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
'''
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