Skip to content

Instantly share code, notes, and snippets.

@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 / 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 / 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 / friday_night.py
Created January 6, 2018 05:25
absl-py example: flags and logging
from __future__ import absolute_import
from __future__ import division
from __future__ import print_function
import sys
from absl import app
from absl import flags
from absl import logging
@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 / 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 / iteration_on_combinations.ipynb
Last active January 15, 2020 21:49
Iteration_on_combinations.ipynb
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@simecek
simecek / facebook_friendship1.r
Created January 18, 2012 11:28
Facebook Friendship Graph
# the code uses 'facebook' function from the previous gist (https://gist.github.com/1634662) or
# see the original http://romainfrancois.blog.free.fr/index.php?post/2012/01/15/Crawling-facebook-with-R
# scrape the list of friends
friends <- facebook( path="me/friends" , access_token=access_token)
# extract Facebook IDs
friends.id <- sapply(friends$data, function(x) x$id)
# extract names
friends.name <- sapply(friends$data, function(x) iconv(x$name,"UTF-8","ASCII//TRANSLIT"))
# short names to initials
@simecek
simecek / sampling_saves_time.ipynb
Last active March 18, 2020 21:41
Sampling_Saves_Time.ipynb
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@simecek
simecek / cured_in_20days.R
Created April 26, 2020 00:46
Comparison to conversions to recovered (20 days gap, ggflags, gganimate)
library(tidyverse)
library(countrycode) # to counvert country names to 2 letter codes
library(ggflags) # for flags
library(gganimate) # for video
# Getting data ------------------------------------------------------------
selected_countries <- c("Italy", "Spain", "France", "Germany",
"Portugal", "United States", "Slovakia", "South Korea", "Japan",
'Belgium', 'Sweden',