Skip to content

Instantly share code, notes, and snippets.

@Ruslan-Skira
Ruslan-Skira / serializers_mapping_keys_data.py
Last active February 16, 2024 10:38
If data has not the same keys and they are with dots in names i customized the to_internal_value function
"""serializers"""
import logging
from collections import Mapping, OrderedDict
from typing import Dict
from django.core.exceptions import ValidationError as DjangoValidationError
from rest_framework import serializers
from rest_framework.exceptions import ValidationError
from rest_framework.fields import get_error_detail, set_value, SkipField
from rest_framework.settings import api_settings
@absent1706
absent1706 / datascience-visualize-grid-cv.py
Created April 7, 2019 08:49
datascience-visualize-grid-cv
def visualize_grid_cv_params(grid_cv):
df = pd.DataFrame(grid_cv.cv_results_['params'])
df['score'] = grid_cv.cv_results_['mean_test_score']
fig, axes = plt.subplots(1, len(grid_cv.param_grid), sharey=True, figsize=(15,4))
i = 0
for param in grid_cv.param_grid:
data = df.groupby(param).mean()['score'].to_dict()
param_values = list(data.keys())
@absent1706
absent1706 / Pagination.php
Last active May 31, 2017 22:51
PHP pagination class
<?php
class Pagination
{
public $page;
public $totalCount;
public $perPage;
public $hasNext;
public $hasPrev;
/*
* If you have
* .oneline {
* overflow: hidden;
* white-space: nowrap;
* text-overflow: ellipsis
* }
*
* inside Bootstrap's .media-body, i.g.:
*
<?php
$the_folder = '.';
$zip_file_name = '1.zip';
$download_file= true;
//$delete_file_after_download= true; doesnt work!!
class FlxZipArchive extends ZipArchive {
STACKDRIVER_ERROR_FILE = '/var/log/app_engine/custom_logs/errors.log.json'
def log_stackdriver_err(request=None, exception=None, user=None):
'''
send error to StackDriver Error Reporting service
see https://cloud.google.com/error-reporting/docs/setup/app-engine-flexible-environment
'''
def make_path_to_file(filename):
if not os.path.exists(os.path.dirname(filename)):
@absent1706
absent1706 / sqlalchemy_debug_utils.py
Last active March 27, 2017 14:32
SQLAlchemy debug utils
def to_sql(query, dialect_name=None):
from sqlalchemy import dialects
import operator
if dialect_name:
dialect_module = getattr(dialects, dialect_name)
if not dialect_module:
raise KeyError('Wrong dialect {}'.format(dialect_name))
dialect = dialect_module.dialect()
else:
@absent1706
absent1706 / activate.bat
Last active March 2, 2017 11:25
knowstory-env
@echo off
set "ROOT_DIR=E:\code\knowstory"
set "VIRTUAL_ENV=%ROOT_DIR%\env"
if defined _OLD_VIRTUAL_PROMPT (
set "PROMPT=%_OLD_VIRTUAL_PROMPT%"
) else (#!E:\Python\python.exe
import re
import sys
@ankurk91
ankurk91 / xdebug-mac.md
Last active March 9, 2024 22:20
php xDebug v3 on Ubuntu/Mac and phpStorm

🪲 Install and Configure xDebug v3 on MacOS for PhpStorm 🐘

  • Assuming that you have already installed php and apache via Homebrew

  • Install xDebug php extension

pecl channel-update pecl.php.net
pecl clear-cache

pecl install xdebug
@NamPNQ
NamPNQ / .gitconfig
Created February 17, 2016 06:33 — forked from ViktorStiskala/.gitconfig
Pycharm as a default git difftool and git mergetool. Add the following to ~/.gitconfig
[diff]
tool = pycharm
[difftool "pycharm"]
cmd = /usr/local/bin/charm diff "$LOCAL" "$REMOTE" && echo "Press enter to continue..." && read
[merge]
tool = pycharm
keepBackup = false
[mergetool "pycharm"]
cmd = /usr/local/bin/charm merge "$LOCAL" "$REMOTE" "$BASE" "$MERGED"