Skip to content

Instantly share code, notes, and snippets.

@RaD
RaD / middleware.py
Created August 6, 2012 21:20
Keep user sorting and filtering settings of models with Django's admin site
# -*- coding: utf-8 -*-
import re
from django.shortcuts import redirect
PREF_VAR = 'ADMIN_PER_USER_PREF'
ORDER_VAR = 'o'
FILTER_TAIL = '__exact'
PATH = '/admin/storage/'
@RaD
RaD / throttle.py
Created July 15, 2016 11:37
Написал на память декоратор, который ограничивает количество вызовов обёрнутой функции за указанный период времени.
#!/usr/bin/env python3.5
# -*- coding: utf-8 -*-
import functools
import time
class throttle(object):
u"""Ограничивает количество вызовов обёрнутой функции за указанный период времени."""
#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""
Implement a console script that compares speed of sequential and parallel api requests to the demo server:
* Take an argument – number of the requests (N).
* Send N requests sequentially (next requests is sent as soon as reply received) and calculate total time
* Send N requests in parallel and calculate total time
* Print both results (sequential first) and speed coefficient, how much the second way is faster than the first one
@RaD
RaD / isincos.py
Last active February 5, 2017 16:34
#!/usr/bin/env python
import math
OUTBITS = 16
BITS_PER_CYCLE = 16
BITS_PER_QUARTER = BITS_PER_CYCLE - 2
BITS = 8
ONE = 1 << BITS
HALF = ONE / 2
C = 70710 * ONE / 100000
@RaD
RaD / lintrunner.py
Created December 30, 2016 07:30
Flake8 integration
#!/usr/bin/env python
"""
Install packages:
wajig install pylint pyflakes pep8 pychecker
pip install flake8
"""
import os
@RaD
RaD / examples.py
Created September 29, 2016 22:22
Some Django related stuff
# -*- coding: utf-8 -*-
import os
from datetime import timedelta
from django.utils import timezone
from django.db import models
from django.utils.translation import ugettext_lazy as _
class Vehicle(models.Model):
@RaD
RaD / gisrest.py
Created September 15, 2016 06:21
Simple RESTful service on Flask with CRUD and GIS
# requirements: flask-restful
import math
from flask import Flask
from flask_restful import Resource, Api, abort, reqparse
app = Flask(__name__)
api = Api(app)
#!/usr/bin/env python
import gtk
import os
import subprocess
clipboard = gtk.clipboard_get()
stand_info = clipboard.wait_for_contents('TEXT').data.strip().split('\n')
product_url = stand_info[0]
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import os
import pwd
import sys
from datetime import datetime
EMAIL = u'zhevak@mail.ru'
@RaD
RaD / i3lock.sh
Created April 27, 2016 05:35
Cool feature for original i3lock
#!/bin/bash
scrot ~/.i3/locker.png -e 'convert $f -blur 5x4 ~/.i3/locker-blurred.png && composite -gravity center ~/.i3/icon_100.png ~/.i3/locker-blurred.png ~/.i3/locker-composed.png'
rm -f ~/.i3/locker.png ~/.i3/locker-blurred.png
i3lock -b -i ~/.i3/locker-composed.png