Skip to content

Instantly share code, notes, and snippets.

@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)
@RaD
RaD / proxy.py
Last active January 16, 2019 15:34
simple http proxy
# -*- coding: utf-8 -*-
import argparse
import re
import requests
from bs4 import BeautifulSoup, Comment
from flask import Flask
from flask import Response
@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
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
@RaD
RaD / who_faster.py
Created March 25, 2016 11:39
To remember dump question about mutable types.
#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""
python who_faster.py
step 1
check_list 5.89978313446
check_set 0.0123991966248
check_dict 0.063777923584
step 2
#!/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
#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""
Implement a console script that solves the standard Queens puzzle:
* Take an argument – size of the board (N).
* Place N chess queens on an N×N chessboard so that no two queens threaten each other.
* Print the number of possible solutions.
* Print the time that was required to solve the problem.