Skip to content

Instantly share code, notes, and snippets.


Philipp Chapkovski chapkovski

  • Higher School of Economics
  • Moscow, Russia
View GitHub Profile
chapkovski / plot_code.r
Created Jan 15, 2021
plot for impeachment year - weight
View plot_code.r
p_load('dplyr', 'estimatr', 'tidyverse', 'readxl', 'sjPlot', 'emmeans', 'olsrr', 'writexl', 'gtsummary', 'stargazer', 'magrittr', 'ggplot2', 'scales','lemon','knitr','ggpmisc', 'fastDummies','kableExtra','wesanderson','viridis','Hmisc','ggpubr','broom','purrr','car','rstatix', 'modelsummary', 'latex2exp', 'pastecs','skimr','haven', 'hrbrthemes','kableExtra', 'skimr','lubridate', 'data.table','ggthemes','summarytools','ggsci','gt','plm','png', 'RCurl', 'jpeg','grid','ggtext')
# forecasts are made using linear regression
df<- data.frame(id_=c(1,2,3,4),year=c(1868,
chapkovski / time_check_decorator
Created Apr 10, 2020
simple decorator to measure time spent on method
View time_check_decorator
import time
def time_check(func):
def wrapper(*args, **kwargs):
start_time = time.time()
func(*args, **kwargs)
print(f"Time spent on {func.__name__}: {(time.time() - start_time)} seconds ---")
return wrapper
chapkovski /
Last active Mar 7, 2020
Locust test for oTree session
from locust import HttpLocust, TaskSet, task, between
from gevent import GreenletExit
from locust.exception import StopLocust
<title>Bot completed</title>
<body>Bot completed</body>
chapkovski /
Last active Feb 23, 2019
Matching based on priorities
class GroupingWaitPage(WaitPage):
_allow_custom_attributes = True
group_by_arrival_time = True
def get_unique(self, wp, priority, filtering=None, matched=None):
seen = set()
# we don't need to re-use matched players
if matched:
wp = [w for w in wp if w not in matched]
View gist:5c7c34667882c3a159cfdc0aa515a4a2
def do_extends(parser, token):
nodelist = parser.parse()
if nodelist.get_nodes_by_type(ExtendsNode):
raise TemplateSyntaxError("'%s' cannot appear more than once in the same template" % bits[0])
chapkovski / eb_logs
Created Oct 13, 2017
full logs of failed docker app
View eb_logs
Retrieving logs...
============= i-0cf01772cd6dc384f ==============
Operations to perform:
Synchronize unmigrated apps: messages, staticfiles
Apply all migrations: contenttypes, admin, sessions, auth
Synchronizing apps without migrations:
Creating tables...
chapkovski /
Created Sep 18, 2017
solution to "how to pass the parameter to a form during formset creation"
import floppyforms.__future__ as forms
from .models import SendReceive, Player
from django.forms import inlineformset_factory, BaseFormSet, BaseInlineFormSet
class SRForm(forms.ModelForm):
class Meta:
model = SendReceive
fields = ['amount_sent']