Skip to content

Instantly share code, notes, and snippets.

View eprikazc's full-sized avatar

eprikazc

View GitHub Profile
@eprikazc
eprikazc / queryset_with_custom_count.py
Last active November 11, 2025 17:49
Queryset with customizable .count() method
from typing import Callable
from django.db import connection
from django.db import models
from django.views.generic import ListView
class QuerySetWithCustomCount:
"""Wrapper for Queryset class that replaces .count() method with a custom callable"""
@eprikazc
eprikazc / gist:f5bdd37c91043ac3f0cecd6c669c28a6
Created February 19, 2021 10:30
Pytest pipeline in bitbucket
# Template python-build
# This template allows you to validate your python code.
# The workflow allows running tests and code linting on the default branch.
image: python:3.8
pipelines:
default:
- parallel:
@eprikazc
eprikazc / request_body_middleware.py
Created August 18, 2017 12:25
Middleware to work around Sentry-DRF compatibility issue
class RequestBodyMiddleware(object):
def __init__(self, get_response):
self.get_response = get_response
def __call__(self, request):
"""
Access request.body before request.
We need it for request.body to still be accessible after request
for example while handling exceptions in Sentry
See https://github.com/encode/django-rest-framework/issues/4050
<key id="start_date" for="node" attr.name="start_date" attr.type="string" tag="true" />
from requests_futures.sessions import FuturesSession
def hello(future):
print(future.result().text)
s = FuturesSession(max_workers=10)
future = s.get('http://requestb.in/tedj6fte')
future.add_done_callback(hello)
import re
INPUT = 'in.txt'
OUTPUT = 'out.txt'
with open(INPUT, 'r') as input_file:
data = input_file.read().strip()
data = re.sub(r'a', r'b', data)
{
'ringdowns': [
{'uid': 'user1-long-uid'},
,,,
],
'hoots': [
{
'uid': 'user2-long-uid',
'position': 1,
},
{
"children": {
"_": {
"children": {
"_": {
"children": {},
"data": {
"id": "c0d2e6e84b0fa99d4ea351e3308822b0",
"name": "angeltorontostaging-vm",
"pvt_type": "vmbox"
<html>
<head>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js"></script>
<script>
$(document).ready(function(){
$.getJSON('http://prope.rs/api/<username>', function(props) {
$(props).each(function(id) {
root = $('<li />').addClass('prop').append(
'<span class="text" />',
'<br/>',