Skip to content

Instantly share code, notes, and snippets.

emakarov

Block or report user

Report or block emakarov

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@emakarov
emakarov / hello_world.rb
Created Aug 18, 2019
Hello World Examples
@emakarov
emakarov / sample.sql
Created Apr 3, 2019
clickhouse user cpu calculation
View sample.sql
create temporary table cputime (dt Date, ts Int8, cpu Int8, user_id Int8);
insert into cputime values
('2019-01-01', 1, 0, 1), ('2019-01-01', 2, 1, 1), ('2019-01-01', 3, 1, 1),
('2019-01-01', 4, 0, 1), ('2019-01-01', 5, 2, 1), ('2019-01-01', 6, 3, 1),
('2019-01-01', 1, 0, 2), ('2019-01-01', 2, 4, 2), ('2019-01-01', 3, 5, 2),
('2019-01-01', 4, 0, 2), ('2019-01-01', 5, 8, 2), ('2019-01-01', 6, 15, 2),
('2019-01-01', 7, 5, 2), ('2019-01-01', 8, 8, 2), ('2019-01-01', 9, 8, 2);
select
@emakarov
emakarov / delete_kubernetes_pods_by_mask
Created Dec 14, 2018
How to delete all kubernetes pods by mask from bash command line
View delete_kubernetes_pods_by_mask
kubectl get pods | grep enter_your_mask_here | while read line ; do echo "$line" | awk '{print $1}' | sort | while read line2; do kubectl delete pod "$line2" ; done; done
@emakarov
emakarov / test_coding_style.py
Created Jul 11, 2018
How to check python coding style automatically via flake8 and isort in django project with unit test
View test_coding_style.py
"""
Coding styles test.
You need to install flake8 and isort via pip.
pip install flake8
pip install isort
Add this test to any of your django apps tests.
"""
import subprocess
@emakarov
emakarov / gist:5a76573c22e52b74e10390779106f4ce
Last active Apr 27, 2018
Delete untagged docker images (with force)
View gist:5a76573c22e52b74e10390779106f4ce
# this removes <none> docker images
docker rmi -f $(docker images -f "dangling=true" -q)
@emakarov
emakarov / merger.py
Last active Apr 6, 2017
Python script that can resolve all git conflicts in some file marked with conflicts based on chosen strategy
View merger.py
accept = 'ours' # ours for 'HEAD' #theirs for other's - choose strategy here for all conflicts
filename = 'enter your filename here'
fresult = '{}.{}'.format(filename, 'merged') # result will be near your file with name `original_filename.ext.merged`
with open(filename) as f:
content = f.readlines()
res = open(fresult, 'w')
to_write = True
merging = False
@emakarov
emakarov / get_last_migration.py
Created Dec 16, 2016
How to get name of last migration in django
View get_last_migration.py
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
from django.core.management.base import BaseCommand, CommandError
from django.db import DEFAULT_DB_ALIAS, connections
from django.db.migrations.loader import MigrationLoader
# code from command showmigrations is used and adopted as a function
def get_migrations(connection, app_names=None):
"""
@emakarov
emakarov / admin.py
Last active Dec 10, 2016
Automatic django admin classes generation snippet
View admin.py
from django.contrib import admin
from django.apps import apps
from django.contrib.admin.sites import AlreadyRegistered
def register_all_models(models):
for m in models:
m_admin_name = m.__module__.replace(".","") + m.__name__ + 'Admin'
ModelAdminClass = type(m_admin_name, (admin.ModelAdmin,), {'set_x': lambda x,y: x.y})
ModelAdminClass.model = m
You can’t perform that action at this time.