Skip to content

Instantly share code, notes, and snippets.

View LowerDeez's full-sized avatar
🇺🇦
Focusing

Oleg Kleshchunov LowerDeez

🇺🇦
Focusing
  • Kyiv, Ukraine
  • 18:44 (UTC +03:00)
View GitHub Profile
@LowerDeez
LowerDeez / admin.py
Last active February 17, 2023 05:15
Django. Admin Tabular Inline initial data
from django.utils.functional import curry
class DetailsInline(admin.TabularInline):
model = Details
# formset = DetailsFormset
extra = 3
def get_formset(self, request, obj=None, **kwargs):
initial = []
if request.method == "GET":
@unpluggedcoder
unpluggedcoder / views.py
Last active January 16, 2020 10:57
Use corresponding serializer class for different request method in Django Rest Framework - Part 3
# views.py
from rest_framework import exceptions
from rest_framework import generics
from myapp import models
from myapp import serializers as ser
class MethodSerializerView(object):
'''
@cobusc
cobusc / protected_media.md
Last active August 31, 2021 17:32
Protected Media in Django

Protected Media in Django

Introduction

Django manages media based on the following definitions:

BASE_DIR = /var/praekelt/telkom-spliceworks/
MEDIA_ROOT = "%s/media/" % BASE_DIR
@iandmyhand
iandmyhand / django_absolute_sum.py
Last active January 8, 2023 08:10
Django ORM function to sum absolute values.
from django.db.models import Sum
class AbsoluteSum(Sum):
name = 'AbsoluteSum'
template = '%(function)s(%(absolute)s(%(expressions)s))'
def __init__(self, expression, **extra):
super(AbsoluteSum, self).__init__(
expression, absolute='ABS ', output_field=IntegerField(), **extra)
@innocuo
innocuo / convert_key.sh
Created March 16, 2017 15:17
Convert PuTTY .ppk key to OpenSSH in Ubuntu
sudo apt-get install putty-tools
#private keys
puttygen your_private_key.ppk -O private-openssh -o your_new_key
chmod 600 your_new_key
#public keys
puttygen your_public_key.ppk -O public-openssh
#based on answer at superuser
@lkrone
lkrone / ean13-label-sheet.py
Created December 16, 2016 22:43
Shows a way to generate a PDF (with Python and ReportLab) of a sheet of labels containing EAN-13 Barcodes and a short, descriptive text.
#!/usr/bin/env python3
from reportlab.lib.pagesizes import A4
from reportlab.graphics.shapes import Drawing, String
from reportlab.graphics.barcode.eanbc import Ean13BarcodeWidget
from reportlab.graphics import renderPDF
from reportlab.pdfgen.canvas import Canvas
"""
Adjust pagesize, number of labels, barcode size and
@brunogaspar
brunogaspar / README.md
Last active October 7, 2022 09:08
Install wkhtmltopdf on Ubuntu (14.04 64-bit) or (16.04 64-bit)

Install wkhtmltopdf on Ubuntu

This was tested on:

  • Ubuntu 14.04 x64
  • Ubuntu 16.04 x64

Installation

@danni
danni / fields.py
Created March 8, 2016 08:52
Multi Choice Django Array Field
from django import forms
from django.contrib.postgres.fields import ArrayField
class ChoiceArrayField(ArrayField):
"""
A field that allows us to store an array of choices.
Uses Django 1.9's postgres ArrayField
and a MultipleChoiceField for its formfield.
@ostcar
ostcar / gist:eb78515a41ab41d1755b
Last active October 28, 2023 10:34
Adds a _id suffix to PrimaryKeyRelatedField
class IdManyRelatedField(ManyRelatedField):
field_name_suffix = '_ids'
def bind(self, field_name, parent):
self.source = field_name[:-len(self.field_name_suffix)]
super().bind(field_name, parent)
class IdPrimaryKeyRelatedField(PrimaryKeyRelatedField):
"""

Git DMZ Flow

I've been asked a few times over the last few months to put together a full write-up of the Git workflow we use at RichRelevance (and at Precog before), since I have referenced it in passing quite a few times in tweets and in person. The workflow is appreciably different from GitFlow and its derivatives, and thus it brings with it a different set of tradeoffs and optimizations. To that end, it would probably be helpful to go over exactly what workflow benefits I find to be beneficial or even necessary.

  • Two developers working on independent features must never be blocked by each other
    • No code freeze! Ever! For any reason!
  • A developer must be able to base derivative work on another developer's work, without waiting for any third party
  • Two developers working on inter-dependent features (or even the same feature) must be able to do so without interference from (or interfering with) any other parties
  • Developers must be able to work on multiple features simultaneously, or at lea