Skip to content

Instantly share code, notes, and snippets.

@vlad-bezden
vlad-bezden / json_serializer.py
Created October 24, 2017 00:42
JSON Serializer for Python objects not serializable by default (date and datetime)
import json
from datetime import date, datetime
def to_json(obj):
'''JSON serializer for objects not serializable by default'''
if isinstance(obj, (datetime, date)):
return obj.isoformat()
raise TypeError (f'Type {type(obj)} not serializable')
@vlad-bezden
vlad-bezden / stock_info.py
Last active October 9, 2018 13:57
Example of how to get financial data from yahoo finance and plot it using matplotlib
import datetime as dt
import matplotlib.pyplot as plt
from matplotlib import style
import pandas as pd
import pandas_datareader.data as web
style.use('ggplot')
start = dt.datetime(2000, 1, 1)
end = dt.date.today()
@vlad-bezden
vlad-bezden / asyncio-async-await.py
Created July 4, 2017 17:22
Example on how to run in parallel more than one task using asyncio and async/await
import asyncio
MAX_TASKS = 5
async def hello():
print('Hello')
await asyncio.sleep(3)
print('World!')
def main():
@vlad-bezden
vlad-bezden / timer.py
Last active May 17, 2017 02:00
context based timer for calculating time
from time import perf_counter
from contextlib import contextmanager
@contextmanager
def timer(label: str):
'''Context Manager for calculating time.
Note:
code example is based on Python 3.6
@vlad-bezden
vlad-bezden / jupyter_ipython_unittest.ipynb
Last active July 26, 2021 13:42
Example of how to use unittest in IPython or Jupyter
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@vlad-bezden
vlad-bezden / Chaining and Permutations.ipynb
Created April 25, 2017 11:38
Example of Chaining and Permutation/Crossproduct using list comprehension in Python
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

flattenArray

Flattens any array dimension to one dimensional array using ES2015 reduce function and recursion

A Pen by Vlad Bezden on CodePen.

License.

@vlad-bezden
vlad-bezden / last-element-of-the-array.markdown
Created March 17, 2017 19:18
Last element of the array
@vlad-bezden
vlad-bezden / index.html
Created March 17, 2017 01:07
Variations of Stateless Functional Components
<div id="app" />