Skip to content

Instantly share code, notes, and snippets.

View vladimirmyshkovski's full-sized avatar
🎯
Focusing

Vladimir Myshkovski vladimirmyshkovski

🎯
Focusing
View GitHub Profile
@kravietz
kravietz / preload.py
Last active January 12, 2022 20:42
Resource hints (dns-prefetch, preload, prerender etc) middleware for Django. Includes automated resource discovery.
#!/usr/bin/python
# -*- coding: utf-8 -*-
from urllib.parse import urlparse
import codecs
from django.conf import settings
from django.utils.html_parser import HTMLParser
__author__ = 'Paweł Krawczyk'
@0mkara
0mkara / Ethereum_private_network.md
Last active June 6, 2025 12:54
Ethereum private network configuration guide.

Create your own Ethereum private network

Introduction

Used nodes:

Linux raspberrypi 4.9.41-v7+ #1023 SMP Tue Aug 8 16:00:15 BST 2017 armv7l GNU/Linux
Linux localhost.localdomain 4.14.5-200.fc26.x86_64 #1 SMP Mon Dec 11 16:29:08 UTC 2017 x86_64 x86_64 x86_64 GNU/Linux
# sample implementation for http://stackoverflow.com/questions/37851053/django-query-group-by-month#new-answer
from __future__ import unicode_literals
from django.db import models
from django.db.models import Func, F, Sum
from django.db.transaction import atomic, rollback
from django.utils.timezone import now
class Invoice(models.Model):
@mwpastore
mwpastore / 00README.md
Last active July 15, 2025 19:15
Lightning Fast WordPress: Caddy+Varnish+PHP-FPM

README

This gist assumes you are migrating an existing site for www.example.com — ideally WordPress — to a new server — ideally Ubuntu Server 16.04 LTS — and wish to enable HTTP/2 (backwards compatibile with HTTP/1.1) with always-on HTTPS, caching, compression, and more. Although these instructions are geared towards WordPress, they should be trivially extensible to other PHP frameworks, other FastCGI backends, and even non-FastCGI backends (using proxy in lieu of fastcgi in the terminal Caddyfile stanza).

Quickstart: Use your own naked and canonical domain names instead of example.com and www.example.com and customize the Caddyfile and VCL provided in this gist to your preferences!

These instructions target Varnish Cache 4.1, PHP-FPM 7.0, and Caddy 0.10. (I'm using MariaDB 10.1 as well, but that's not relevant to this guide.)

import functools
from channels.handler import AsgiRequest
from rest_framework.exceptions import AuthenticationFailed
from rest_framework.settings import api_settings
authenticators = [auth() for auth in api_settings.DEFAULT_AUTHENTICATION_CLASSES]
import bleach
import json as jsonlib
from django import template
from django.utils.safestring import mark_safe
register = template.Library()
@register.filter
def json(value):
@jackton1
jackton1 / drf_optimize.py
Last active October 6, 2023 22:37
Optimize Django Rest Framework model views queries.
from django.db import ProgrammingError, models
from django.db.models.constants import LOOKUP_SEP
from django.db.models.query import normalize_prefetch_lookups
from rest_framework import serializers
from rest_framework.utils import model_meta
class OptimizeModelViewSetMetaclass(type):
"""
This metaclass optimizes the REST API view queryset using `prefetch_related` and `select_related`
if the `serializer_class` is an instance of `serializers.ModelSerializer`.
@mcihad
mcihad / main.go
Created September 4, 2018 19:35
Check standart django password in go language
package main
import (
"crypto/sha256"
"encoding/base64"
"fmt"
"golang.org/x/crypto/pbkdf2"
"strconv"
"strings"
)
@cb109
cb109 / UserInitials.vue
Last active October 15, 2020 09:19
Vuetify User Initials Avatar
<template>
<v-avatar v-if="user !== null"
:size="size"
:style="{'background-color': backgroundColor}">
<strong class="initials"
:style="{'color': fontColor,
'font-size': fontSize}">
{{ (user.first_name[0] + user.last_name[0]) || '?' }}
</strong>
@vladimirmyshkovski
vladimirmyshkovski / drf_optimize.py
Created December 23, 2018 18:09 — forked from jackton1/drf_optimize.py
MetaClass to Improve DRF ModelViewsSet query.
from django.db import ProgrammingError, models
from django.db.models.constants import LOOKUP_SEP
from django.db.models.query import normalize_prefetch_lookups
from rest_framework import serializers
from rest_framework.utils import model_meta
class OptimizeRelatedModelViewSetMetaclass(type):
"""
This metaclass optimizes the queryset using `prefetch_related` and `select_related`.