Skip to content

Instantly share code, notes, and snippets.

View vladimirmyshkovski's full-sized avatar
🎯
Focusing

Vladimir Myshkovski vladimirmyshkovski

🎯
Focusing
View GitHub Profile
@pomber
pomber / timeago.js
Created February 14, 2020 17:22
Get a time ago human friendly string from a date (like dates in twitter).
const MINUTE = 60,
HOUR = MINUTE * 60,
DAY = HOUR * 24,
YEAR = DAY * 365;
function getTimeAgo(date) {
const secondsAgo = Math.round((+new Date() - date) / 1000);
if (secondsAgo < MINUTE) {
return secondsAgo + "s";
@Lightnet
Lightnet / gunjstrustsharekey.js
Last active January 28, 2021 09:14
gunjstrustsharekeyv3
/*
Self contain Sandbox Gun Module chain for auth sea.js:
Created by: Lightnet
License: MIT
Version: 3.0
Last Update:2019.08.17
Credit: amark ( https://github.com/amark/gun)
Status(Work in progress!):
@ThinkingJoules
ThinkingJoules / GunDBpermissionExample.js
Created April 25, 2019 15:29
GunDB group permissions example. Restrict reads and/or writes.
//CLIENT
Gun.on('opt', function (ctx) {
if (ctx.once) {
return
}
this.to.next(ctx)
ctx.on('auth', function(msg){
let to = this.to
clientAuth(ctx)
function clientAuth(ctx){
@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`.
@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>
@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"
)
@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`.
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):
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]
@mwpastore
mwpastore / 00README.md
Last active April 18, 2024 06:21
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.)