Skip to content

Instantly share code, notes, and snippets.

View chapkovski's full-sized avatar

Philipp Chapkovski chapkovski

View GitHub Profile
@chapkovski
chapkovski / plot_code.r
Created January 15, 2021 08:46
plot for impeachment year - weight
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 April 10, 2020 18:45
simple decorator to measure time spent on method
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 March 7, 2020 19:20
Locust test for oTree session
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 February 23, 2019 10:47
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]
@chapkovski
chapkovski / gist:5c7c34667882c3a159cfdc0aa515a4a2
Created August 10, 2018 13:09
copypaste from django extends tag
@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 October 13, 2017 15:41
full logs of failed docker app
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 September 18, 2017 09:42
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']