Skip to content

Instantly share code, notes, and snippets.

View LowerDeez's full-sized avatar
🇺🇦
Focusing

Oleg Kleshchunov LowerDeez

🇺🇦
Focusing
  • Kyiv, Ukraine
  • 19:07 (UTC +03:00)
View GitHub Profile
@bradmontgomery
bradmontgomery / week_range.py
Created March 7, 2013 19:27
Given a Date, calculate the first/last dates for the week. This assumes weeks start on Sunday and end on Saturday (common in the US).
from datetime import timedelta
def week_range(date):
"""Find the first & last day of the week for the given day.
Assuming weeks start on Sunday and end on Saturday.
Returns a tuple of ``(start_date, end_date)``.
"""
@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):
'''
@omarryhan
omarryhan / Sanic-Gino-Alembic migrations Setup
Last active May 30, 2020 15:49
Sanic/Gino/Alembic migrations
# Do the first 6 steps only once.
1. pip install --user alembic
2. bash: ``cd {{my_project}} && alembic init alembic``
3. bash: ``text_editor {{my_project}}/alembic.ini``
4. Change: "sqlalchemy.url = postgres://{{username}}:{{password}}@{{address}}/{{db_name}}"
5. bash: ``text_editor {{my_project}}/alembic/env.py``
6. Now, import your metadata/db object from your app.:
# {{my_project}}/{{my_project_dir}}/app.py
@sweenzor
sweenzor / gist:2933958
Created June 15, 2012 00:52
Kill all celery tasks (redis)
# nuke the queue
redis-cli FLUSHALL
# nuke anything currently running
pkill -9 celeryd
@johtso
johtso / gist:5881137
Last active February 18, 2021 18:37
Django Rest Framework underscore <-> camelcase conversion
import re
from rest_framework import serializers, renderers, parsers
class JSONRenderer(renderers.JSONRenderer):
def render(self, data, *args, **kwargs):
if data:
data = recursive_key_map(underscore_to_camelcase, data)
return super(JSONRenderer, self).render(data, *args, **kwargs)
@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
# HANDLER
from django.utils.translation import ugettext_lazy as _
from rest_framework.exceptions import ErrorDetail
from rest_framework.views import exception_handler
non_field_errors = 'non_field_errors'
def set_custome_errors(errors):
@gauravvjn
gauravvjn / create_sha256_signature.py
Last active February 7, 2022 23:58
Create HMAC SHA256 signature/encryption/encode
"""
https://gist.github.com/Azadehkhojandi/50eaae4cf20b21faef186f2c8ee97873
"""
import hmac
import hashlib
import binascii
def create_sha256_signature(key, message):
@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
@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