This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from django.db import models | |
class BulkGetOrCreateManager(models.Manager): | |
def bulk_get_or_create(self, objs, lookup_field=None): | |
assert lookup_field, "Not set 'lookup_field' for 'bulk_get_or_create'" | |
lookup = {f'{lookup_field}__in': objs} | |
existing_objects = [ | |
obj for obj in self.get_queryset().filter(**lookup) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class StockRouter: | |
route_app_labels = {'stock'} | |
def db_for_read(self, model, **hints): | |
if model._meta.app_label in self.route_app_labels: | |
return 'nq' | |
return None | |
def db_for_write(self, model, **hints): | |
if model._meta.app_label in self.route_app_labels: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import os | |
import uuid | |
from django.core.files import storage as django_storage | |
class LocalMediaStorage(django_storage.FileSystemStorage): | |
def get_available_name(self, name, max_length=None): | |
path, filename = os.path.split(name) | |
name = os.path.join(path, str(uuid.uuid4()), filename) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from django_filters import filters as django_filters | |
class CharInFilter(django_filters.BaseInFilter, django_filters.CharFilter): | |
pass |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from django_filters import rest_framework as filters | |
class FilterSetRequired(filters.FilterSet): | |
def is_valid(self): | |
for filter_name, filter in self.filters.items(): | |
if filter.extra.get('required') and filter_name not in self.data: | |
self.form.add_error(filter_name, 'Query param is required') | |
return super().is_valid() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
docker container ls | awk '{print $1}' | xargs docker container stop 2> /dev/null | |
docker rm $(docker ps -a -q) 2> /dev/null | |
docker images | awk '$1 == "<none>" {print $3}' | xargs docker rmi -f 2> /dev/null |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdio.h> | |
#include <stdlib.h> | |
#include <GL/glew.h> | |
#include <GLFW/glfw3.h> | |
GLFWwindow* window; | |
/* | |
$ gcc -Wall -lGL -lglfw -lGLEW opengl.c -o opengl && ./opengl |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
""" | |
Vtiger CRM 6.3.0 - Authenticated Remote Code Execution | |
Version: 6.3.0 (and lower) | |
Tested on: Linux (Ubuntu) | |
CVE: CVE-2015-6000 | |
""" | |
from __future__ import print_function | |
import argparse |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from tkinter.filedialog import * | |
from tkinter import * | |
import shelve | |
def hello(): | |
information.insert(1.0, "Hello, this version v1.0...\n") | |
def save_dir(): #Считывание директории | |
global put |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
# -*- coding: utf-8 -*- | |
import xmpp | |
class Jabber(object): | |
""" The wrapper class Jabber account """ |