Skip to content

Instantly share code, notes, and snippets.

Avatar

Leonid Shvechikov shvechikov

View GitHub Profile
View local.py
def my_local(init):
key = object()
def getter():
t = _app_ctx_stack.top
l = getattr(t, 'my_locals')
if l is None:
t.my_locals = l = {}
if key not in l:
l[key] = init()
return l[key]
View olimp_128.py
def find(diamonds, share, shift=0, skip=()):
for i in range(shift, len(diamonds)):
if i in skip:
continue
d = diamonds[i]
if d > share:
continue
View gist:c28a08db6aac6f65a72e
from inspect import getattr_static
class dep:
name = None
def __init__(self, type):
self.type = type
View gist:6c339ddaf143ed5ac468
__author__ = 'archeg'
import httplib
import urllib
import urllib2
import re
def URLRequest(url, params, headers, method="GET"):
if method == "POST":
View json_editor_debug.log
jsoneditor.js:4923 []
jsoneditor.js:4923 []
jsoneditor.js:4923 []
jsoneditor.js:4923 []
jsoneditor.js:4923 []
jsoneditor.js:4923 []
jsoneditor.js:4923 []
jsoneditor.js:4923 []
jsoneditor.js:4923 []
jsoneditor.js:4923 []
View tmux_cheatsheet.markdown

tmux cheatsheet

As configured in my dotfiles.

start new:

tmux

start new with session name:

View preview_decorator.py
def add_preview_for(*fields):
"""
This is a decorator for model classes that adds preview methods.
So instead of manually adding preview methods:
>>> class Student(models.Model):
... photo = models.ImageField()
... icon = models.ImageField()
...
View find_best_subarray.py
def find_best_subarray(array):
best_sum = 0
best_start = 0
best_end = 0
cur_sum = 0
cur_start = 0
cur_end = 0
for i, x in enumerate(array):
@shvechikov
shvechikov / signed_s3_upload.py
Created Apr 28, 2016
Upload files to S3 using generated signed URLs
View signed_s3_upload.py
import requests
from boto.s3.connection import S3Connection
c = S3Connection(AWS_ACCESS_KEY, AWS_SECRET_KET)
data = 'file content'
filename = 'dir/name.txt'
bucket_name = 'your-bucket-name'
headers = {'Content-Type': 'text/plain'}
View mongo_auth_middleware.py
"""
This module is no more needed. It could be useful for implementing Django-level authentication.
Now it works using DRF-level authentication -- dating.apps.mongo_auth.authentication.MongoTokenAuthentication.
So it's here JFYI.
"""
# from django.contrib import auth
from django.utils.functional import SimpleLazyObject
from .models import User, AnonymousUser