Skip to content

Instantly share code, notes, and snippets.

View OndrejIT's full-sized avatar
🧨

Ondřej Bárta OndrejIT

🧨
View GitHub Profile
@OndrejIT
OndrejIT / auto_format.py
Created March 13, 2023 10:14
auto_format.py
# Author Ondrej Barta
# [email protected]
# Copyright 2023
from thumbor.filters import BaseFilter, filter_method
from thumbor.utils import logger
# http://css.nothrem.cz/jak-urcit-kvalitu-a-kompresi-jpg-obrazku/
@OndrejIT
OndrejIT / minswap.py
Last active June 24, 2022 09:17
minswap telegram bot
import requests
from datetime import datetime
TOKENS = 1000
TELEGRAM_API = "https://api.telegram.org/botXY" # Telegra api bot token
TELEGRAM_CHAT_ID = 0 # Telegram chat ID
def get_price():
url = "https://monorepo-mainnet-prod.minswap.org/graphql?CandlestickSeries"
var mediaJSON = { "categories" : [ { "name" : "Movies",
"videos" : [
{ "description" : "Big Buck Bunny tells the story of a giant rabbit with a heart bigger than himself. When one sunny day three rodents rudely harass him, something snaps... and the rabbit ain't no bunny anymore! In the typical cartoon tradition he prepares the nasty rodents a comical revenge.\n\nLicensed under the Creative Commons Attribution license\nhttp://www.bigbuckbunny.org",
"sources" : [ "http://commondatastorage.googleapis.com/gtv-videos-bucket/sample/BigBuckBunny.mp4" ],
"subtitle" : "By Blender Foundation",
"thumb" : "images/BigBuckBunny.jpg",
"title" : "Big Buck Bunny"
},
{ "description" : "The first Blender Open Movie from 2006",
"sources" : [ "http://commondatastorage.googleapis.com/gtv-videos-bucket/sample/ElephantsDream.mp4" ],
class CachedPaginator(Paginator):
"""
Paginator that does not count the rows in the table.
"""
@cached_property
def count(self):
"""Return the total number of objects, across all pages."""
try:
md5 = hashlib.md5(str(self.object_list.query).encode("utf-8")).hexdigest()
cache_key = "admin_paginator:{0}".format(md5)
@OndrejIT
OndrejIT / admin.py
Last active March 29, 2023 20:27
PermissionVersionAdmin
class PermissionVersionAdmin(VersionAdmin):
def _reversion_revisionform_view(self, request, version, *args, **kwargs):
if not request.user.is_superuser:
messages.error(request, "Revert is supported only super user.")
return redirect("{}:{}_{}_change".format(self.admin_site.name, self.opts.app_label, self.opts.model_name), object_id=version.object_id)
else:
return super()._reversion_revisionform_view(request, version, *args, **kwargs)
@OndrejIT
OndrejIT / search.py
Created October 18, 2017 11:50
search.py
def search(query):
try:
query.encode("ascii")
except UnicodeEncodeError:
galleries = Gallery.objects.published().filter(
fulltext__full_ts=SearchQuery(query, config="czech")
)
if not galleries:
galleries = Gallery.objects.published().filter(title__icontains=query)
else:
# Author Ondrej Barta
# [email protected]
# Copyright 2017
import av
from PIL import Image
video_path = "/home/ondrej/Pictures/sample/video/video.mp4"
intro_path = "/home/ondrej/Pictures/sample/video/video2.mp4"
output_path = "/home/ondrej/OUTPUT.mp4"
# Author Ondrej Barta
# [email protected]
# Copyright 2017
from django.conf import settings
from rest_framework import authentication, permissions
class BasicAuthentication(authentication.BasicAuthentication):
def authenticate_credentials(self, userid, password):
def auth_check(func=None, realm="private", text="Access denied"):
"""Wrapper na basic/token/IP autorizaci"""
@wraps(func)
def wrapper(*args, **kwargs):
# FIXME otestovat o proti nginx a caddy
remote_ip = IP(request.get_header("X-Real-IP", request.remote_addr))
local_ip = IPSet([IP("10.0.0.0/8"), IP("172.16.0.0/12"), IP("192.168.0.0/16")])
if remote_ip in local_ip:
return func(*args, **kwargs)
class Base64(BaseStorage):
"""
Trida reprezentujici cteni a vraceni z base64
"""
def copy(self, output_url, delete=False):
output_storage = storage_driver(output_url)
data = self.read()
output_storage.upload(data)