Skip to content

Instantly share code, notes, and snippets.

Avatar

Philipp Chapkovski chapkovski

  • Higher School of Economics
  • Moscow, Russia
View GitHub Profile
@chapkovski
chapkovski / plot_code.r
Created Jan 15, 2021
plot for impeachment year - weight
View plot_code.r
library('pacman')
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,
1998,
2019,
2021),
@chapkovski
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
chapkovski / locust_for_otree.py
Last active Mar 7, 2020
Locust test for oTree session
View locust_for_otree.py
from locust import HttpLocust, TaskSet, task, between
from gevent import GreenletExit
from locust.exception import StopLocust
BOT_COMPLETE_HTML_MESSAGE = b'''
<html>
<head>
<title>Bot completed</title>
</head>
<body>Bot completed</body>
@chapkovski
chapkovski / pages.py
Last active Feb 23, 2019
Matching based on priorities
View pages.py
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
@register.tag('extends')
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
chapkovski / eb_logs
Created Oct 13, 2017
full logs of failed docker app
View eb_logs
Retrieving logs...
============= i-0cf01772cd6dc384f ==============
-------------------------------------
/var/log/eb-docker/containers/eb-current-app/ea01c38c37d7-stdouterr.log
-------------------------------------
Operations to perform:
Synchronize unmigrated apps: messages, staticfiles
Apply all migrations: contenttypes, admin, sessions, auth
Synchronizing apps without migrations:
Creating tables...
@chapkovski
chapkovski / forms.py
Created Sep 18, 2017
solution to "how to pass the parameter to a form during formset creation"
View forms.py
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']