Skip to content

Instantly share code, notes, and snippets.

@simecek
simecek / reflected-operands.ipynb
Created October 26, 2019 00:20
Reflected Operands
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@simecek
simecek / save_env.py
Last active October 6, 2019 06:57
Save all objects from your session into a single compressed file
import __main__
import pickle
from bz2 import BZ2File
from gzip import GzipFile
from typing import Optional, List
def save_env(path: str, objects: Optional[List[str]] = None, compress: str = 'gzip', protocol: int = -1):
"""
Save the environment (list of objects) of Jupyter Notebook into a compressed file
@simecek
simecek / time_measuring_decorator.ipynb
Created June 9, 2019 06:47
Time_measuring_decorator.ipynb
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@simecek
simecek / number-of-instances.ipynb
Created May 26, 2019 21:10
Number Of instances.ipynb
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@simecek
simecek / valentine.py.R
Created February 14, 2019 21:00
R/Python Valentine Script
s = 'Python is awesome!'
red = "#FA5882"
a = eval("exec('import sys; import matplotlib.pyplot as plt; import numpy as np; print(s); t = np.arange(0,2*np.pi, 0.1); x = 16*np.sin(t)**3; y = 13*np.cos(t)-5*np.cos(2*t)-2*np.cos(3*t)-np.cos(4*t); plt.fill(x,y,color=red); plt.show(); sys.exit()')")
print('R is great too!')
X11() # Use windows() or qartz() if on Windows or Mac
t = seq(0, 2*pi, by=0.1)
x = 16*sin(t)^3
y = 13*cos(t) - 5*cos(2*t) - 2*cos(3*t) - cos(4*t)
plot(x=x, y=y, type="n", xlab="", ylab="")
polygon(x=x, y=y, col=red, border=red)
@simecek
simecek / numpy-append-is-slow.ipynb
Created December 18, 2018 11:45
Numpy append is slow.ipynb
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@simecek
simecek / reprlibdemo.ipynb
Created November 4, 2018 22:13
ReprlibDemo.ipynb
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
# Likes per tweet plot
# Analyze user's data downloaded from Twitter
library(jsonlite)
library(tidyverse)
# download your data from Twitter (Settings and Privacy, Your Twitter data), unzip the folder
setwd("~/Downloads/twitter-2018-10-29-6c18f5c0ab3605451f73cd0fd9ed186a2fd5b2caf1812ab747d42351da805656/")
json <- readLines("tweet.js")
@simecek
simecek / debug-magic.ipynb
Created September 23, 2018 00:02
Debug magic.ipynb
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@simecek
simecek / draw_board.R
Last active September 13, 2018 16:45
if (!require(tidyverse)) {
install.packages("tidyverse")
library(tidyverse)
}
# Game of Life visualisation
draw_board <- function(board) {
# number of rows and columns
M = nrow(board)