Skip to content

Instantly share code, notes, and snippets.

View Sinkler's full-sized avatar
:octocat:
Saluton!

Anton Shurashov Sinkler

:octocat:
Saluton!
View GitHub Profile
@Sinkler
Sinkler / aiocache_emcache_backend.py
Created August 20, 2021 14:10
The emcache backend for the aiocache library
import asyncio
import typing
import emcache
from aiocache.base import BaseCache
from aiocache.serializers import BaseSerializer
import settings
@Sinkler
Sinkler / db.py
Created August 15, 2019 12:42
Django Postgres Copy From
import csv
from io import StringIO
from django.db import connection
from psycopg2 import sql
def copy_from(model, columns, records):
"""
copy_from(
@Sinkler
Sinkler / settings.py
Created July 22, 2019 15:23
Show SQL traceback in Django
if os.environ.get('DEBUG_SQL') or os.environ.get('DEBUG_SQL_TRACEBACK'):
LOGGING['loggers']['django.db.backends'] = {
'level': 'DEBUG',
'handlers': ['console'],
'propagate': False,
}
if os.environ.get('DEBUG_SQL_TRACEBACK'):
import traceback
import logging
@Sinkler
Sinkler / shuffle_random_playlist.scpt
Created February 25, 2018 12:18
iTunes Apple Script - Create a shuffled playlist from another one
(function () {
'use strict';
function toLower(s) {
return s.toLowerCase();
}
function makeArray(length) {
return Array.from(new Array(length), (x,i) => i);
}
# coding=utf-8
# from cashculator export to debit & credit import
import csv
file_name = 'out.csv'
def convert_date(date):
data = {
@Sinkler
Sinkler / index.coffee
Created June 24, 2015 13:58
jQuery Bar Rating - stars with CSS3
$ '#id_rating'
.barrating(
wrapperClass: 'rating-bar'
showSelectedRating: false
initialRating: 5
)
@Sinkler
Sinkler / gist:326795023c12cc3149af
Created June 18, 2015 17:41
Django RedirectSeoMiddleware
class RedirectSeoMiddleware(object):
"""
Insert before django.middleware.common.CommonMiddleware
"""
def process_request(self, request):
if not request.path.endswith('/'):
try:
view, args, kwargs = resolve(request.path + '/')
kwargs['request'] = request
view(*args, **kwargs)
@Sinkler
Sinkler / gist:bfc2099235ac96937f34
Created October 13, 2014 21:27
Flask-OAuthlib sample config: twitter, facebook, instagram, vk
# Twitter
from app.config import TWITTER_APP_KEY, TWITTER_APP_SECRET
twitter_oauth = oauth.remote_app(
'twitter',
consumer_key=TWITTER_APP_KEY,
consumer_secret=TWITTER_APP_SECRET,
base_url='https://api.twitter.com/1.1/',
request_token_url='https://api.twitter.com/oauth/request_token',