Skip to content

Instantly share code, notes, and snippets.

View marcmuon's full-sized avatar

Marc Kelechava marcmuon

View GitHub Profile
@marcmuon
marcmuon / snowflake_hour_floor.sql
Created September 1, 2021 20:07
Floor function on Hour in Snowflake
select GETDATE() --2021-09-01 19:35:22
select time_slice(getdate()::timestamp_ntz, 1, 'HOUR') --2021-09-01 19:00:00
@marcmuon
marcmuon / fast_fib.py
Created December 4, 2018 23:49
compute large fibonacci numbers very fast
def fib_to(n):
fibs = [0, 1]
for i in range(2, n+1):
fibs.append(fibs[-1] + fibs[-2])
return fibs
print(fib_to(40000)[33399])
@marcmuon
marcmuon / ecdf.py
Last active November 8, 2018 00:14
Convert sample (list) of data to x,y lists in order to plot eCDF
import numpy as np
def ecdf(sample):
n = len(sample)
x = np.sort(sample)
y = np.arange(1, len(x)+1) / n
return x, y
@marcmuon
marcmuon / derivative.py
Last active October 26, 2018 22:04
Derivative Calculation in Python - example using f'(1/x)
def derivative(f, x):
h = 0.00000001
return (f(x+h) - f(x)) / h
x=10
approx_derivative = derivative(lambda x: 1/x, x)
actual = -1/(x*x)
print('approx:', approx_derivative,', actual:', actual)